#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') {
      f = -1;
    }
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
struct edge {
  int nxt, to, w;
} e1[N << 1], e2[N << 1], e[N << 1];
int n, m, cnt1, head2[N], from[N], to[N], dis[N], num[N], head1[N], cnt2, cnt,
    head[N];
inline void add1(int x, int y) {
  e1[++cnt1].nxt = head1[x];
  e1[cnt1].to = y;
  head1[x] = cnt1;
}
inline void add2(int x, int y) {
  e2[++cnt2].nxt = head2[x];
  e2[cnt2].to = y;
  head2[x] = cnt2;
}
inline void add3(int x, int y, int w) {
  e[++cnt].nxt = head[x];
  e[cnt].w = w;
  e[cnt].to = y;
  head[x] = cnt;
}
bool vis[N], mar[N], sign[N];
inline void dfs1(int x) {
  for (int i = head1[x]; i; i = e1[i].nxt) {
    int y = e1[i].to;
    if (vis[y]) continue;
    vis[y] = 1;
    dfs1(y);
  }
}
inline void dfs2(int x) {
  for (int i = head2[x]; i; i = e2[i].nxt) {
    int y = e2[i].to;
    if (mar[y]) continue;
    mar[y] = 1;
    dfs2(y);
  }
}
inline void spfa() {
  queue<int> q;
  memset(vis, 0, sizeof(vis));
  memset(dis, -0x3f3f3f3f, sizeof(dis));
  q.push(1);
  vis[1] = 1;
  dis[1] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = false;
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].to;
      if (dis[v] < dis[u] + e[i].w) {
        dis[v] = dis[u] + e[i].w;
        if (!vis[v]) {
          q.push(v);
          num[v]++;
        }
        if (num[v] > n) {
          puts("No");
          exit(0);
        }
      }
    }
  }
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int u, v;
    u = read(), v = read();
    add1(u, v);
    add2(v, u);
    from[i] = u;
    to[i] = v;
  }
  dfs1(1);
  dfs2(n);
  for (int i = 1; i <= n; i++) {
    if (vis[i] && mar[i]) {
      sign[i] = 1;
    }
  }
  sign[1] = 1, sign[n] = 1;
  for (int i = 1; i <= m; i++) {
    if (sign[from[i]] && sign[to[i]]) {
      add3(from[i], to[i], 1);
      add3(to[i], from[i], -2);
    }
  }
  spfa();
  puts("Yes");
  for (int i = 1; i <= m; i++) {
    if (sign[from[i]] && sign[to[i]]) {
      printf("%d\n", dis[to[i]] - dis[from[i]]);
    } else
      puts("1");
  }
  return 0;
}
