#include <bits/stdc++.h>
using namespace std;
int n, m, flag;
int vis1[(1000 + 5)], vis2[(1000 + 5)], vis[(1000 + 5)], u[(5000 + 5)],
    v[(5000 + 5)], ok[(1000 + 5)], dis[(1000 + 5)], cnt[(1000 + 5)];
vector<int> edge1[(1000 + 5)], edge2[(1000 + 5)], e[(1000 + 5)], w[(1000 + 5)];
void dfs1(int u) {
  vis1[u] = 1;
  for (int i = 0; i < edge1[u].size(); i++) {
    int now = edge1[u][i];
    if (!vis1[now]) vis1[now] = 1, dfs1(now);
  }
}
void dfs2(int u) {
  vis2[u] = 1;
  for (int i = 0; i < edge2[u].size(); i++) {
    int now = edge2[u][i];
    if (!vis2[now]) vis2[now] = 1, dfs2(now);
  }
}
void SPFA(int Begin) {
  queue<int> q;
  q.push(Begin);
  memset(dis, -0x3f, sizeof(dis));
  vis[Begin] = 1, dis[Begin] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = 0; i < e[u].size(); i++) {
      int now = e[u][i];
      if (dis[now] < dis[u] + w[u][i]) {
        dis[now] = dis[u] + w[u][i];
        if (!vis[now]) {
          cnt[now]++;
          q.push(now);
        }
        if (cnt[now] > n) {
          flag = 1;
          return;
        }
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u[i], &v[i]);
    edge1[u[i]].push_back(v[i]);
    edge2[v[i]].push_back(u[i]);
  }
  dfs1(1);
  dfs2(n);
  for (int i = 1; i <= n; i++)
    if (vis1[i] && vis2[i]) ok[i] = 1;
  for (int i = 1; i <= m; i++) {
    if (ok[u[i]] && ok[v[i]]) {
      e[u[i]].push_back(v[i]);
      e[v[i]].push_back(u[i]);
      w[u[i]].push_back(1);
      w[v[i]].push_back(-2);
    }
  }
  SPFA(1);
  if (flag) {
    printf("No");
    return 0;
  }
  printf("Yes\n");
  for (int i = 1; i <= m; i++) {
    if (ok[u[i]] && ok[v[i]])
      printf("%d\n", dis[v[i]] - dis[u[i]]);
    else
      printf("1\n");
  }
  return 0;
}
