#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
int n, m, s, t;
int len;
struct edge {
  int u, v;
  int next;
};
edge G[100100];
int h[maxn];
int vis[maxn];
vector<int> vec;
bool flag;
int star;
void init() {
  for (int i = 0; i < maxn; i++) {
    h[i] = -1;
  }
}
bool dfs(int x, int v) {
  if (vis[v] == 2) {
    star = v;
    return true;
  }
  vis[v] = 2;
  for (int i = h[v]; i != -1; i = G[i].next) {
    if (i != x) {
      int to = G[i].v;
      if (vis[to] == 0) {
        if (dfs(x, to)) return true;
      } else if (vis[to] == 2) {
        star = to;
        return true;
      }
    }
  }
  vis[v] = 1;
  return false;
}
bool dfsa(int x, int v) {
  if (vis[v] == 2) return true;
  vis[v] = 2;
  for (int i = h[v]; i != -1; i = G[i].next) {
    if (i != x) {
      int to = G[i].v;
      if (vis[to] == 0) {
        vec.push_back(i);
        if (dfsa(x, to)) return true;
        vec.pop_back();
      } else if (vis[to] == 2) {
        vec.push_back(i);
        return true;
      }
    }
  }
  vis[v] = 1;
  return false;
}
int main() {
  while (~scanf("%d%d", &n, &m) && (n || m)) {
    init();
    len = 0;
    int ta, tb;
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &ta, &tb);
      G[len].u = ta;
      G[len].v = tb;
      G[len].next = h[ta];
      h[ta] = len++;
    }
    flag = false;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (dfs(-1, i)) {
        flag = true;
        break;
      }
    }
    if (!flag) {
      puts("YES");
      return 0;
    }
    memset(vis, 0, sizeof vis);
    dfsa(-1, star);
    for (int i = 0; i < vec.size(); i++) {
      memset(vis, 0, sizeof vis);
      flag = false;
      for (int j = 1; j <= n; j++) {
        if (dfs(vec[i], j)) {
          flag = true;
          break;
        }
      }
      if (!flag) break;
    }
    if (!flag)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
