#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch - '0' < 0 || ch - '0' > 9) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch - '0' >= 0 && ch - '0' <= 9) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m;
struct P {
  int x, y;
} e[5010];
int head[1010], nxt[5010 * 2], to[5010 * 2], c[5010 * 2], tot;
void add(int u, int v, int x) {
  tot++;
  nxt[tot] = head[u];
  head[u] = tot;
  to[tot] = v;
  c[tot] = x;
}
int vis1[1010], vis2[1010];
queue<int> q;
void bfs(int st, int *A) {
  q.push(st);
  A[st] = 1;
  while (q.size()) {
    int now = q.front();
    q.pop();
    for (int i = head[now]; i; i = nxt[i]) {
      if (!A[to[i]]) {
        A[to[i]] = 1;
        q.push(to[i]);
      }
    }
  }
}
int in[1010];
int cnt[1010];
int dis[1010];
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) e[i].x = read(), e[i].y = read();
  for (int i = 1; i <= m; i++) add(e[i].x, e[i].y, 1);
  bfs(1, vis1);
  tot = 0;
  memset(head, 0, sizeof(head));
  for (int i = 1; i <= m; i++) add(e[i].y, e[i].x, 1);
  bfs(n, vis2);
  if (!vis1[n]) {
    puts("No");
    return 0;
  }
  tot = 0;
  memset(head, 0, sizeof(head));
  for (int i = 1; i <= m; i++) {
    if (vis1[e[i].x] && vis1[e[i].y] && vis2[e[i].x] && vis2[e[i].y]) {
      add(e[i].x, e[i].y, 2);
      add(e[i].y, e[i].x, -1);
    }
  }
  memset(dis, 125, sizeof(dis));
  q.push(1);
  dis[1] = 0;
  in[1] = 1;
  while (q.size()) {
    int now = q.front();
    q.pop();
    in[now] = 0;
    cnt[now]++;
    if (cnt[now] > m) {
      puts("No");
      return 0;
    }
    for (int i = head[now]; i; i = nxt[i]) {
      if (dis[to[i]] > dis[now] + c[i]) {
        dis[to[i]] = dis[now] + c[i];
        if (!in[to[i]]) {
          q.push(to[i]);
          in[to[i]] = 1;
        }
      }
    }
  }
  puts("Yes");
  for (int i = 1; i <= m; i++) {
    if (vis1[e[i].x] && vis1[e[i].y] && vis2[e[i].x] && vis2[e[i].y])
      printf("%d\n", dis[e[i].y] - dis[e[i].x]);
    else
      printf("%d\n", rand() % 2 + 1);
  }
  return 0;
}
