#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = f;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return f * x;
}
inline void write(int x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
struct node {
  int v, a, b, next;
} e[10000];
int head[10000], n, m, cnt, dis[10000], vis[10000];
int vis1[10000], x[10000], y[10000], sig[10000];
void add(int a, int b, int v) {
  cnt++;
  e[cnt].a = a;
  e[cnt].b = b;
  e[cnt].v = v;
  e[cnt].next = head[a];
  head[a] = cnt;
}
int spfa(int sta) {
  queue<int> q;
  dis[sta] = 0;
  vis[sta] = 1;
  q.push(sta);
  while (!q.empty()) {
    int tem = q.front();
    sig[tem]++;
    if (sig[tem] > m) return 0;
    q.pop();
    vis[tem] = 0;
    for (int i = head[tem]; i != -1; i = e[i].next) {
      if (dis[e[i].b] > dis[tem] + e[i].v) {
        dis[e[i].b] = dis[tem] + e[i].v;
        if (!vis[e[i].b]) {
          vis[e[i].b] = 1;
          q.push(e[i].b);
        }
      }
    }
  }
  return 1;
}
void dfs(int x, int t) {
  vis1[x]++;
  if (t == 1 && x == n) return;
  if (t == 2 && x == 1) return;
  for (int i = head[x]; i != -1; i = e[i].next) {
    if (!vis1[e[i].b] && t == 1 || vis1[e[i].b] == 1 && t == 2) {
      dfs(e[i].b, t);
    }
  }
}
int main() {
  srand(time(0));
  memset(head, -1, sizeof(head));
  memset(dis, 1e6, sizeof(dis));
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    x[i] = read(), y[i] = read();
    add(x[i], y[i], 1);
  }
  dfs(1, 1);
  cnt = 0, memset(head, -1, sizeof(head));
  for (int i = 1; i <= m; i++) add(y[i], x[i], 1);
  dfs(n, 2);
  if (vis1[n] < 2) {
    putchar('N'), putchar('o');
    return 0;
  }
  cnt = 0, memset(head, -1, sizeof(head));
  for (int i = 1; i <= m; i++) {
    if (vis1[x[i]] == 2 && vis1[y[i]] == 2)
      add(x[i], y[i], 2), add(y[i], x[i], -1);
  }
  if (spfa(1)) {
    putchar('Y'), putchar('e'), putchar('s'), putchar('\n');
    for (int i = 1; i <= m; i++) {
      if (vis1[x[i]] == 2 && vis1[y[i]] == 2) {
        write(dis[y[i]] - dis[x[i]]), putchar('\n');
      } else {
        write(rand() % 2 + 1), putchar('\n');
      }
    }
  } else
    putchar('N'), putchar('o');
  return 0;
}
