#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 10, M = 10000 + 10;
int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int to[M], nt[M], w[M], hd[N], tot = 1;
void add(int x, int y, int z) {
  ++tot, to[tot] = y, nt[tot] = hd[x], w[tot] = z, hd[x] = tot;
}
int n, m, e[M][2], di[N], cn[N];
bool v1[N], v2[N], v[N];
queue<int> q;
int main() {
  n = rd(), m = rd();
  for (int i = 1; i <= m; ++i) {
    e[i][0] = rd(), e[i][1] = rd();
    add(e[i][0], e[i][1], 0), add(e[i][1], e[i][0], 0);
  }
  v1[1] = 1, q.push(1);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = hd[x]; i; i = nt[i]) {
      if (i & 1) continue;
      int y = to[i];
      if (!v1[y]) v1[y] = 1, q.push(y);
    }
  }
  v2[n] = 1, q.push(n);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = hd[x]; i; i = nt[i]) {
      if ((i ^ 1) & 1) continue;
      int y = to[i];
      if (!v2[y]) v2[y] = 1, q.push(y);
    }
  }
  memset(hd, 0, sizeof(hd)), tot = 1;
  for (int i = 1; i <= m; ++i) {
    int x = e[i][0], y = e[i][1];
    if (v1[x] && v2[x] && v1[y] && v2[y]) add(y, x, -1), add(x, y, 2);
  }
  memset(di, 0x3f3f3f, sizeof(di));
  di[1] = 0, v[1] = 1, q.push(1);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = hd[x]; i; i = nt[i]) {
      int y = to[i];
      if (di[y] > di[x] + w[i]) {
        di[y] = di[x] + w[i];
        cn[y] = cn[x] + 1;
        if (cn[y] > n) {
          puts("No");
          return 0;
        }
        if (!v[y]) v[y] = 1, q.push(y);
      }
    }
    v[x] = 0;
  }
  puts("Yes");
  for (int i = 1; i <= m; ++i) {
    int x = e[i][0], y = e[i][1];
    printf("%d\n", 1 + (di[y] - di[x] == 2));
  }
  return 0;
}
