#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int M = 5010;
struct node {
  int nxt, to, dis;
} g[M << 1];
int head[N], cnt;
int x[M], y[M];
int sum[N];
int vis[N];
vector<int> g2[N], g3[N];
int n, m;
inline void dfs2(int u) {
  vis[u] |= 1;
  for (int i = 0; i < g2[u].size(); i++) {
    int v = g2[u][i];
    if (!(vis[v] & 1)) dfs2(v);
  }
}
inline void dfs3(int u) {
  vis[u] |= 2;
  for (int i = 0; i < g3[u].size(); i++) {
    int v = g3[u][i];
    if (!(vis[v] & 2)) dfs3(v);
  }
}
inline void addedge(int u, int v, int dis) {
  g[++cnt].nxt = head[u];
  g[cnt].to = v;
  g[cnt].dis = dis;
  head[u] = cnt;
}
int dist[N];
bool inq[N];
inline void spfa() {
  queue<int> q;
  q.push(1);
  inq[1] = 1;
  dist[1] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inq[u] = 0;
    for (int i = head[u]; i; i = g[i].nxt) {
      int v = g[i].to;
      if (dist[v] < dist[u] + g[i].dis) {
        dist[v] = dist[u] + g[i].dis;
        if (!inq[v]) inq[v] = 1, q.push(v), sum[v]++;
        if (sum[v] >= n) {
          puts("No");
          exit(0);
        }
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x[i], &y[i]);
    g2[x[i]].push_back(y[i]);
    g3[y[i]].push_back(x[i]);
  }
  dfs2(1);
  dfs3(n);
  for (int i = 1; i <= m; i++) {
    if (vis[x[i]] == 3 && vis[y[i]] == 3) {
      addedge(x[i], y[i], 1);
      addedge(y[i], x[i], -2);
    }
  }
  memset(dist, 128, sizeof(dist));
  spfa();
  puts("Yes");
  for (int i = 1; i <= m; i++) {
    if (vis[x[i]] == 3 && vis[y[i]] == 3) {
      printf("%d\n", dist[y[i]] - dist[x[i]]);
    } else {
      printf("%d\n", 1);
    }
  }
}
