#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, z[509], x[509], pi, g, s;
vector<int> v[509];
bool m, rr;
pair<int, int> p[509];
void dfs(int w) {
  if (m == 1) return;
  z[w] = 1;
  for (vector<int>::iterator it = v[w].begin(); it != v[w].end(); it++) {
    if (x[(*it)] == c) {
      p[pi].first = w;
      p[pi].second = (*it);
      pi++;
      m = 1;
      g = (*it);
      return;
    }
    if (z[(*it)] == 0) {
      x[(*it)] = c;
      p[pi].first = w;
      p[pi].second = (*it);
      pi++;
      dfs((*it));
      if (m == 1) return;
    }
  }
  x[w] = 0;
}
void dfss(int w) {
  if (rr == 1) {
    x[w] = 0;
    return;
  }
  z[w] = d + 1;
  for (vector<int>::iterator it = v[w].begin(); it != v[w].end(); it++) {
    if ((((*it) == p[d].second && w == p[d].first))) continue;
    if (x[(*it)] == d + 1) {
      s = 1;
      rr = 1;
      x[w] = 0;
      return;
    }
    if (z[(*it)] != d + 1) {
      x[(*it)] = d + 1;
      dfss((*it));
      if (rr == 1) {
        x[w] = 0;
        return;
      }
    }
  }
  x[w] = 0;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> a >> b;
  for (c = 1; c <= b; c++) {
    cin >> d >> e;
    v[d].push_back(e);
  }
  for (c = 1; c <= a; c++) {
    if (z[c] == 0) {
      x[c] = c;
      dfs(c);
      if (m == 1) break;
    }
  }
  if (g == 0) {
    cout << "YES";
    return 0;
  }
  for (d = 0; d < pi; d++) {
    if (p[d].first == g) break;
  }
  for (c = 0; c <= 502; c++) z[c] = 0, x[c] = 0;
  for (d = d; d < pi; d++) {
    for (c = 1; c <= a; c++) {
      if (z[c] != d + 1) {
        x[c] = d + 1;
        rr = 0;
        dfss(c);
        if (rr == 1) break;
      }
    }
    if (rr == 0) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}
