#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > g;
vector<long long> used;
vector<long long> cyc;
vector<long long> p;
long long stx, sty;
long long oo = 0;
void dfs(long long v) {
  used[v] = 1;
  for (auto i : g[v]) {
    if (v == stx && i == sty) continue;
    if (!used[i]) {
      dfs(i);
    } else if (used[i] == 1) {
      oo = 1;
      throw 1;
    }
  }
  used[v] = 2;
}
void cycle(long long v) {
  used[v] = 1;
  for (auto i : g[v]) {
    if (!used[i]) {
      p[i] = v;
      cycle(i);
    } else if (used[i] == 1) {
      cyc.push_back(i);
      while (v != i) {
        cyc.push_back(v);
        v = p[v];
      }
      cyc.push_back(i);
      throw 1;
    }
  }
  used[v] = 2;
}
int main() {
  long long n, m;
  cin >> n >> m;
  g.resize(n);
  used.resize(n, 0);
  p.resize(n);
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    g[a - 1].push_back(b - 1);
  }
  for (long long i = 0; i < n; i++) {
    try {
      if (!used[i]) cycle(i);
    } catch (...) {
      if (!cyc.empty()) break;
    }
  }
  if (0) {
    cout << cyc.size() << "\n";
    for (auto i : cyc) {
      cout << i << " ";
    }
    cout << "\n";
  }
  if (cyc.empty()) return cout << "YES", 0;
  long long sz = cyc.size();
  for (long long i = 1; i < sz; i++) {
    stx = cyc[i - 1];
    sty = cyc[i];
    swap(stx, sty);
    oo = 0;
    try {
      used.assign(n, 0);
      for (long long j = 0; j < n; j++) {
        if (!used[j]) {
          dfs(j);
        }
      }
    } catch (...) {
    }
    if (!oo) {
      return cout << "YES", 0;
    }
  }
  cout << "NO";
  return 0;
}
