#include <bits/stdc++.h>
using namespace std;
void in(int &x) {
  register int c = getchar();
  x = 0;
  for (; (c < 48 || c > 57); c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
}
const int N = 1e5 + 5;
std::vector<int> g[N], tg[N];
pair<int, int> edges[N * 5];
bool vis[N], tvis[N];
int dist[N];
void dfs(int v, int p) {
  vis[v] = true;
  for (int u : g[v])
    if (!vis[u]) {
      dfs(u, v);
    }
}
void tdfs(int v, int p) {
  tvis[v] = true;
  for (int u : tg[v])
    if (!tvis[u]) {
      tdfs(u, v);
    }
}
int main() {
  int n, m, i, j, u, v;
  in(n);
  in(m);
  for (i = 0; i < m; i++) {
    in(u);
    in(v);
    edges[i] = make_pair(u, v);
    g[u].push_back(v), tg[v].push_back(u);
  }
  dfs(1, 0);
  tdfs(n, 0);
  for (i = 1; i < n; i++) {
    for (j = 0; j < m; j++) {
      int u = edges[j].first, v = edges[j].second;
      if (vis[u] && tvis[v]) {
        dist[v] = max(dist[v], dist[u] + 1);
        dist[u] = max(dist[u], dist[v] - 2);
      }
    }
  }
  for (i = 0; i < m; i++) {
    int u = edges[i].first, v = edges[i].second;
    if (vis[u] && tvis[v])
      if (!(dist[v] - dist[u] == 2 || dist[v] - dist[u] == 1)) {
        puts("No");
        return 0;
      }
  }
  puts("Yes");
  for (i = 0; i < m; i++) {
    int u = edges[i].first, v = edges[i].second;
    if (vis[u] && tvis[v])
      printf("%d\n", dist[v] - dist[u]);
    else
      printf("1\n");
  }
  return 0;
}
