#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline int getc() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  register int ret = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    ret = ret * 10 + ch - 48;
    ch = getchar();
  }
  return f ? -ret : ret;
}
struct node {
  int nex, to, val;
} e[1000005];
int head[1000005], sum[1000005], cnt;
int dis[1000005];
bool vis[1000005];
int n, m, u[1000005], v[1000005];
inline void add(int u, int v, int w) {
  e[++cnt].nex = head[u];
  e[cnt].to = v;
  e[cnt].val = w;
  head[u] = cnt;
}
inline bool SPFA(int s) {
  queue<int> q;
  memset(vis, 0, sizeof(vis));
  memset(sum, 0, sizeof(sum));
  memset(dis, 0x3f, sizeof(dis));
  q.push(s);
  dis[s] = 0;
  vis[s] = 1;
  ++sum[s];
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (register int i = head[u]; i; i = e[i].nex) {
      int v = e[i].to;
      if (dis[v] > dis[u] + e[i].val) {
        dis[v] = dis[u] + e[i].val;
        if (vis[v] == 0) {
          vis[v] = 1;
          ++sum[u];
          q.push(v);
          if (sum[v] >= n + 2) return 1;
        }
      }
    }
  }
  return 0;
}
bool book1[1000005], book2[1000005];
void dfs(int x, bool* v) {
  v[x] = 1;
  for (register int i = head[x]; i; i = e[i].nex)
    if (!v[e[i].to]) dfs(e[i].to, v);
}
int main() {
  n = read();
  m = read();
  for (register int i = 1; i <= m; ++i) {
    u[i] = read();
    v[i] = read();
    add(u[i], v[i], 1);
  }
  dfs(1, book1);
  memset(head, 0, sizeof(head));
  cnt = 0;
  for (register int i = 1; i <= m; ++i) {
    add(v[i], u[i], 1);
  }
  dfs(n, book2);
  memset(head, 0, sizeof(head));
  cnt = 0;
  for (register int i = 1; i <= m; ++i) {
    if (book1[u[i]] & book1[v[i]] & book2[u[i]] & book2[v[i]]) {
      add(u[i], v[i], 2);
      add(v[i], u[i], -1);
    }
  }
  if (SPFA(1) || dis[n] == 0x3f3f3f3f) return 0 * puts("No");
  puts("Yes");
  for (register int i = 1; i <= m; ++i) {
    if (book1[u[i]] & book1[v[i]] & book2[u[i]] & book2[v[i]]) {
      printf("%d\n", dis[v[i]] - dis[u[i]]);
    } else {
      printf("1\n");
    }
  }
  return 0;
}
