#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
vector<int> g[100001], fg[100001];
int head[100001], n, m, tot, col1[100001], col2[100001];
struct edge {
  int to, nxt, dis;
} e[100001];
int dis[100001], vis[100001], cnt[1000001];
inline void made(int from, int to, int dis) {
  e[++tot].to = to;
  e[tot].nxt = head[from];
  head[from] = tot;
  e[tot].dis = dis;
}
void dfs1(int u) {
  col1[u] = 1;
  for (auto v : g[u]) {
    if (!col1[v]) dfs1(v);
  }
}
void dfs2(int u) {
  col2[u] = 1;
  for (auto v : fg[u]) {
    if (!col2[v]) dfs2(v);
  }
}
pair<int, int> que[100001];
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    que[i] = make_pair(x, y);
    g[x].push_back(y);
    fg[y].push_back(x);
  }
  dfs1(1);
  dfs2(n);
  for (int u = 1; u <= n; u++) {
    for (auto v : g[u]) {
      if (col1[u] && col2[v]) made(u, v, 1), made(v, u, -2);
    }
  }
  queue<int> dl;
  while (!dl.empty()) dl.pop();
  dl.push(1);
  memset(dis, 0x80, sizeof dis);
  dis[1] = 0;
  vis[1] = 1;
  while (!dl.empty()) {
    int u = dl.front();
    dl.pop();
    vis[u] = 0;
    if (cnt[u] >= n) {
      printf("No\n");
      return 0;
    }
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].to;
      if (dis[v] < dis[u] + e[i].dis) {
        dis[v] = dis[u] + e[i].dis;
        cnt[v] = cnt[u] + 1;
        if (!vis[v]) {
          dl.push(v);
          vis[v] = 1;
        }
      }
    }
  }
  printf("Yes\n");
  for (int i = 1; i <= m; i++) {
    int u = que[i].first, v = que[i].second;
    if (col1[u] && col2[v]) {
      printf("%d\n", dis[v] - dis[u]);
    } else {
      printf("1\n");
    }
  }
  return 0;
}
