#include <bits/stdc++.h>
const int Maxn = 10010;
using namespace std;
struct Eadg {
  int v, t, nxt;
} e[Maxn * 5];
int head[Maxn], Cnt;
void add(int u, int v, int t) {
  e[++Cnt].v = v, e[Cnt].t = t, e[Cnt].nxt = head[u], head[u] = Cnt;
}
int dis[Maxn], book[Maxn], cnt[Maxn], n, m;
queue<int> q;
bool SPAF() {
  memset(dis, -0x3f, sizeof(dis));
  dis[1] = 0, book[1] = 1, cnt[1] = 1;
  q.push(1);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    book[x] = 0;
    if (cnt[x] > n) return false;
    for (int i = head[x]; i; i = e[i].nxt) {
      int y = e[i].v, z = e[i].t;
      if (dis[y] < dis[x] + z) {
        dis[y] = dis[x] + z;
        if (!book[y]) q.push(y), book[y] = 1, cnt[y]++;
      }
    }
  }
  return true;
}
int vis[Maxn], vis2[Maxn];
vector<int> E1[Maxn], E2[Maxn];
void dfs1(int now) {
  vis[now] = 1;
  for (int i = 0; i < E1[now].size(); i++) {
    if (vis[E1[now][i]]) continue;
    dfs1(E1[now][i]);
  }
}
void dfs2(int now) {
  vis2[now] = 1;
  for (int i = 0; i < E2[now].size(); i++) {
    if (vis2[E2[now][i]]) continue;
    dfs2(E2[now][i]);
  }
}
int U[Maxn * 5], V[Maxn * 5];
signed main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    U[i] = u, V[i] = v;
    E1[u].push_back(v), E2[v].push_back(u);
  }
  dfs1(1), dfs2(n);
  for (int i = 1; i <= m; i++) {
    if (vis[U[i]] && vis2[V[i]] && vis[V[i]] && vis2[V[i]]) {
      add(U[i], V[i], 1);
      add(V[i], U[i], -2);
    }
  }
  if (!SPAF()) {
    printf("No\n");
  } else {
    printf("Yes\n");
    for (int i = 1; i <= m; i++) {
      if (vis[U[i]] && vis2[V[i]] && vis[V[i]] && vis2[V[i]]) {
        printf("%d\n", dis[V[i]] - dis[U[i]]);
      } else {
        printf("%d\n", 1);
      }
    }
  }
  return 0;
}
