#include <bits/stdc++.h>
using namespace std;
char buf[1 << 15], *fs, *ft;
inline char getc() {
  return (fs == ft &&
          (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft))
             ? 0
             : *fs++;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getc();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getc();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getc();
  }
  return x * f;
}
const int MAXN = 5010;
int n, m, flag, h, t, len, maxx;
int lin[MAXN], nex[MAXN << 2], ver[MAXN << 2];
int q[MAXN * MAXN], ans[MAXN], mark[MAXN], cnt[MAXN], e[MAXN << 2];
int vis[MAXN], v[MAXN], dis[MAXN];
vector<int> g[MAXN], w[MAXN];
struct wy {
  int x, y;
} T[MAXN];
inline void add(int x, int y, int z) {
  ver[++len] = y;
  nex[len] = lin[x];
  lin[x] = len;
  e[len] = z;
}
inline void dfs(int x) {
  ans[x] = 1;
  for (unsigned int i = 0; i < g[x].size(); ++i) {
    int tn = g[x][i];
    if (ans[tn]) continue;
    dfs(tn);
  }
}
inline void dfs1(int x) {
  cnt[x] = 1;
  for (unsigned int i = 0; i < w[x].size(); ++i) {
    int tn = w[x][i];
    if (cnt[tn]) continue;
    dfs1(tn);
  }
}
inline void spfa() {
  while (h++ < t) {
    int x = q[h];
    vis[x] = 0;
    for (int i = lin[x]; i; i = nex[i]) {
      int tn = ver[i];
      if (dis[tn] > dis[x] + e[i]) {
        v[tn] = v[x] + 1;
        if (v[tn] >= n) {
          flag = 1;
          return;
        }
        dis[tn] = dis[x] + e[i];
        if (!vis[tn]) q[++t] = tn, vis[tn] = 1;
      }
    }
  }
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; ++i) {
    int x, y;
    x = read();
    y = read();
    T[i] = (wy){x, y};
    g[x].push_back(y);
    w[y].push_back(x);
  }
  dfs(1);
  dfs1(n);
  for (int i = 1; i <= m; ++i) {
    if (ans[T[i].x] && cnt[T[i].y]) {
      add(T[i].x, T[i].y, 2);
      add(T[i].y, T[i].x, -1);
    } else
      mark[i] = 1;
  }
  h = t = 0;
  for (int i = 1; i <= n; ++i) q[++t] = i, vis[i] = 1;
  spfa();
  if (flag) {
    puts("No");
    return 0;
  }
  puts("Yes");
  for (int i = 1; i <= m; ++i) {
    if (mark[i])
      printf("%d\n", mark[i]);
    else
      printf("%d\n", dis[T[i].y] - dis[T[i].x]);
  }
  return 0;
}
