#include <bits/stdc++.h>
using namespace std;
int n, m, S[1000005], T[1000005], nxt[1000005], head[1000005], to[1000005],
    rnxt[1000005], rhead[1000005], rto[1000005], dist[1000005], times[1000005],
    adj[1000005], tot, rtot;
bool flag1[1000005], flag2[1000005], flag[1000005], inq[1000005];
int NXT[1000005], HEAD[1000005], TO[1000005], ADJ[1000005], TOT;
int read() {
  char c = getchar();
  int ans = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9')
    ans = (ans << 1) + (ans << 3) + (c ^ 48), c = getchar();
  return ans;
}
void add(int u, int v) {
  nxt[++tot] = head[u];
  head[u] = tot;
  to[tot] = v;
  return;
}
void radd(int u, int v) {
  rnxt[++rtot] = rhead[u];
  rhead[u] = rtot;
  rto[rtot] = v;
  return;
}
void ADD(int u, int v, int w) {
  NXT[++TOT] = HEAD[u];
  HEAD[u] = TOT;
  TO[TOT] = v;
  ADJ[TOT] = w;
  return;
}
void DFS(int x) {
  if (flag1[x]) return;
  flag1[x] = 1;
  for (register int i = head[x]; i; i = nxt[i]) DFS(to[i]);
  return;
}
void rDFS(int x) {
  if (flag2[x]) return;
  flag2[x] = 1;
  for (register int i = rhead[x]; i; i = rnxt[i]) rDFS(rto[i]);
  return;
}
void SPFA() {
  for (register int i = 1; i <= n + 1; i++) dist[i] = 1000000000;
  dist[n + 1] = 0;
  queue<int> Q;
  Q.push(n + 1);
  inq[n + 1] = 1;
  while (!Q.empty()) {
    int now = Q.front();
    Q.pop();
    inq[now] = 0;
    times[now]++;
    if (times[now] > n + 10) {
      printf("No");
      exit(0);
    }
    for (register int i = HEAD[now]; i; i = NXT[i])
      if (dist[TO[i]] > dist[now] + ADJ[i]) {
        dist[TO[i]] = dist[now] + ADJ[i];
        if (!inq[TO[i]]) inq[TO[i]] = 1, Q.push(TO[i]);
      }
  }
  int minn = dist[1];
  for (register int i = 2; i <= n; i++) minn = min(minn, dist[i]);
  for (register int i = 1; i <= n; i++) dist[i] -= minn;
  return;
}
int main() {
  n = read(), m = read();
  for (register int i = 1; i <= m; i++)
    S[i] = read(), T[i] = read(), add(S[i], T[i]), radd(T[i], S[i]);
  DFS(1);
  rDFS(n);
  for (register int i = 1; i <= n; i++) flag[i] = (flag1[i] & flag2[i]);
  for (register int i = 1; i <= m; i++)
    if (flag[S[i]] && flag[T[i]]) ADD(S[i], T[i], 2), ADD(T[i], S[i], -1);
  for (register int i = 1; i <= n; i++)
    if (flag[i]) ADD(n + 1, i, 0);
  SPFA();
  printf("Yes\n");
  for (register int i = 1; i <= m; i++)
    if (flag[S[i]] && flag[T[i]])
      printf("%d\n", dist[T[i]] - dist[S[i]]);
    else
      printf("1\n");
  return 0;
}
