#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e4 + 7;
const int INF = 0x3f3f3f3f;
struct node {
  int to, c, next;
} e[MAX];
int cnt = 0;
int head[MAX];
int x[MAX], y[MAX];
int dis[MAX], vis[MAX];
bool judge[MAX];
void add(int x, int y, int z) {
  e[cnt] = {y, z, head[x]};
  head[x] = cnt++;
}
int n, m;
int t[MAX];
void dfs(int x) {
  vis[x] = 1;
  if (x == n) {
    judge[x] = 1;
    return;
  }
  for (int i = head[x]; i != -1; i = e[i].next) {
    if (e[i].c == 2) {
      if (!vis[e[i].to]) dfs(e[i].to);
      if (judge[e[i].to]) judge[x] = 1;
    }
  }
}
void spfa() {
  queue<int> q;
  memset(vis, 0, sizeof vis);
  memset(dis, INF, sizeof dis);
  memset(t, 0, sizeof t);
  vis[1] = 1;
  dis[1] = 0;
  q.push(1);
  t[1]++;
  while (!q.empty()) {
    int u = q.front();
    vis[u] = 0;
    q.pop();
    for (int i = head[u]; i != -1; i = e[i].next) {
      int to = e[i].to;
      int c = e[i].c;
      if (!judge[to]) continue;
      if (dis[to] > dis[u] + c) {
        dis[to] = dis[u] + c;
        if (!vis[to]) {
          vis[to] = 1;
          q.push(to);
          t[to]++;
          if (t[to] >= n) {
            puts("No");
            return;
          }
        }
      }
    }
  }
  puts("Yes");
  for (int i = 1; i <= m; i++) {
    if (dis[y[i]] - dis[x[i]] == 1)
      puts("1");
    else
      puts("2");
  }
}
int main() {
  memset(head, -1, sizeof head);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x[i], &y[i]);
    add(y[i], x[i], -1), add(x[i], y[i], 2);
  }
  dfs(1);
  spfa();
  return 0;
}
