/**
 n m
 a1 b1
 ...
 am bm
*/

#include <cstdio>
#include <vector>
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)

typedef pair <int, int> pii;

const int N = 1e5;
vector<pii> c[N], rc[N];
vector<int> res;
int n, m, cc, u[N];

void dfs( int v ) { // O(V+E)
  u[v] = 1;
  while (c[v].size()) {
    pii p = *c[v].rbegin();
    c[v].pop_back();
    dfs(p.first);
    res.push_back(p.second); // номер ребра
  }
}
int main() {
  scanf("%d%d", &n, &m);
  forn(i, m) {
    int a, b;
    scanf("%d%d", &a, &b), a--, b--; // 0..n-1
    c[a].push_back(pii(b, i));
    rc[b].push_back(pii(a, i));
  }
  forn(i, n)
    if (c[i].size() != rc[i].size()) {
      puts("NO");
      return 0;
    }
  dfs(0);
  if (count(u, u + n, 1) != n) {
    puts("NO");
  }
}