#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int f = 1, sum = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 3) + (sum << 1) + ch - '0';
    ch = getchar();
  }
  return f * sum;
}
const int N = 500010;
int n, m, front[N], cnt;
struct node {
  int to, nxt, w;
} e[N << 1];
struct edge {
  int u, v;
} edg[N];
void Add(int u, int v, int w) {
  e[++cnt] = (node){v, front[u], w};
  front[u] = cnt;
}
vector<int> G[N];
queue<int> Q;
int f[N], g[N];
void bfs1() {
  for (int i = 1; i <= n; i++) G[i].clear();
  for (int i = 1; i <= m; i++) G[edg[i].u].push_back(edg[i].v);
  Q.push(1);
  f[1] = 1;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int v : G[u])
      if (!f[v]) {
        f[v] = 1;
        Q.push(v);
      }
  }
}
void bfs2() {
  for (int i = 1; i <= n; i++) G[i].clear();
  for (int i = 1; i <= m; i++) G[edg[i].v].push_back(edg[i].u);
  Q.push(n);
  g[n] = 1;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int v : G[u])
      if (!g[v]) {
        g[v] = 1;
        Q.push(v);
      }
  }
}
int vis[N], dis[N], add[N];
void spfa() {
  Q.push(1);
  add[1] = 1;
  vis[1] = 1;
  memset(dis, -63, sizeof(dis));
  dis[1] = 0;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    vis[u] = 0;
    if (add[u] > n) {
      puts("No");
      exit(0);
    }
    for (int i = front[u]; i; i = e[i].nxt) {
      int v = e[i].to;
      if (dis[v] < dis[u] + e[i].w) {
        dis[v] = dis[u] + e[i].w;
        if (!vis[v]) {
          vis[v] = 1;
          Q.push(v);
          add[v]++;
        }
      }
    }
  }
}
int main() {
  n = gi();
  m = gi();
  for (int i = 1; i <= m; i++) {
    int u = gi(), v = gi();
    edg[i] = (edge){u, v};
  }
  bfs1();
  bfs2();
  for (int i = 1; i <= m; i++) {
    int u = edg[i].u, v = edg[i].v;
    if (f[u] && f[v] && g[u] && g[v]) {
      Add(v, u, -2);
      Add(u, v, 1);
    }
  }
  spfa();
  puts("Yes");
  for (int i = 1; i <= m; i++) {
    int u = edg[i].u, v = edg[i].v;
    if (f[u] && f[v] && g[u] && g[v])
      printf("%d\n", dis[v] - dis[u]);
    else
      puts("1");
  }
  return 0;
}
