#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005, maxm = 5005;
int n, m, tot, lxt[maxm << 1], head[maxn], ver[maxm << 1], Nxt[maxm << 1],
    head_2[maxn], ver_2[maxm << 1], Nxt_2[maxm << 1], edge_2[maxm << 1], tot_2;
int dis[maxn], ok[maxn];
bool inq[maxn], flag, pd[maxn], vis[maxn];
queue<int> q;
inline void add1(int u, int v) {
  ver[++tot] = v, Nxt[tot] = head[u], lxt[tot] = u, head[u] = tot;
}
int tot_3, head_3[maxm << 1], ver_3[maxm << 1], Nxt_3[maxm << 1];
inline void add3(int u, int v) {
  ver_3[++tot_3] = v, Nxt_3[tot_3] = head_3[u], head_3[u] = tot_3;
}
inline void add_2(int u, int v, int l) {
  ver_2[++tot_2] = v, edge_2[tot_2] = l, Nxt_2[tot_2] = head_2[u],
  head_2[u] = tot_2;
}
inline void dfs1(int u) {
  vis[u] = true;
  for (register int i = head[u]; i; i = Nxt[i]) {
    if (vis[ver[i]]) continue;
    dfs1(ver[i]);
  }
}
inline void dfs2(int u) {
  pd[u] = true;
  for (register int i = head_3[u]; i; i = Nxt_3[i]) {
    if (pd[ver_3[i]]) continue;
    dfs2(ver_3[i]);
  }
}
inline void spfa() {
  for (register int i = 1; i <= n; i++) dis[i] = -999999999;
  q.push(1);
  inq[1] = true, dis[1] = 0, ok[1] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inq[u] = false;
    for (register int i = head_2[u]; i; i = Nxt_2[i]) {
      int v = ver_2[i];
      if (dis[v] < dis[u] + edge_2[i]) {
        dis[v] = dis[u] + edge_2[i];
        if (inq[v]) continue;
        ok[v]++, inq[v] = true, q.push(v);
        if (ok[v] > n) {
          flag = true;
          return;
        }
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1, u, v; i <= m; i++)
    scanf("%d%d", &u, &v), add1(u, v), add3(v, u);
  dfs1(1), dfs2(n);
  for (register int i = 1; i <= m; i++)
    if (vis[lxt[i]] && pd[lxt[i]] && vis[ver[i]] && pd[ver[i]])
      add_2(lxt[i], ver[i], 1), add_2(ver[i], lxt[i], -2);
  spfa();
  if (flag) {
    printf("No");
    return 0;
  }
  printf("Yes\n");
  for (register int i = 1; i <= m; i++) {
    if (vis[lxt[i]] && pd[lxt[i]] && vis[ver[i]] && pd[ver[i]]) {
      printf("%d\n", dis[ver[i]] - dis[lxt[i]]);
    } else {
      printf("1\n");
    }
  }
  return 0;
}
