#include <bits/stdc++.h>
using namespace std;
int block = 400;
const long double eps = 1e-7;
const long long pe = 137;
const long long pe2 = 1181;
const long long N = 1e6 + 200;
const long long mod = 1e9 + 7;
const long long cmod = 998244353;
const long long INF = 1e16;
int n, m, st, ed, nw, nw2;
int was[N], p[N];
vector<int> g[N];
bool cycle = 0;
vector<int> vv;
void dfs(int v) {
  if (st) return;
  was[v] = 1;
  for (auto to : g[v]) {
    if (st) return;
    if (was[to] == 1) {
      st = to, ed = v;
      while (ed != st) {
        vv.push_back(ed);
        ed = p[ed];
      }
      vv.push_back(st);
      return;
    } else if (was[to] == 0) {
      p[to] = v;
      dfs(to);
    }
  }
  was[v] = 2;
}
void dfs2(int v) {
  was[v] = 1;
  for (auto to : g[v]) {
    if (v == nw && to == nw2) continue;
    if (was[to] == 1)
      cycle = 1;
    else if (was[to] == 0)
      dfs2(to);
  }
  was[v] = 2;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) {
    if (!was[i] && !st) {
      dfs(i);
    }
  }
  if (!st) {
    cout << "YES";
    return 0;
  }
  reverse(vv.begin(), vv.end());
  for (int i = 0; i < vv.size(); i++) {
    memset(was, 0, sizeof(was));
    int next = (i + 1) % (int)vv.size();
    nw = vv[i], nw2 = vv[next];
    cycle = 0;
    for (int j = 1; j <= n; j++) {
      if (!was[j] && cycle == 0) {
        dfs2(j);
      }
    }
    if (!cycle) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
}
