#include <bits/stdc++.h>
using namespace std;
bool vst[2][5010];
vector<int> G[5010], rG[5010];
void dfs(int p) {
  vst[0][p] = 1;
  for (__typeof((G[p]).begin()) it = (G[p]).begin(); it != (G[p]).end(); it++)
    if (!vst[0][*it]) dfs(*it);
}
void rdfs(int p) {
  vst[1][p] = 1;
  for (__typeof((rG[p]).begin()) it = (rG[p]).begin(); it != (rG[p]).end();
       it++)
    if (!vst[1][*it]) rdfs(*it);
}
int n, m, a[5010], b[5010], dis[5010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a[i], &b[i]);
    G[a[i]].push_back(b[i]);
    rG[b[i]].push_back(a[i]);
  }
  dfs(1);
  rdfs(n);
  for (int i = 0; i < n; i++) {
    bool upd = 0;
    for (int j = 0; j < m; j++) {
      int u = a[j], v = b[j];
      if (vst[0][u] && vst[1][v]) {
        if (dis[u] > dis[v] - 1) dis[u] = dis[v] - 1, upd = 1;
        if (dis[v] > dis[u] + 2) dis[v] = dis[u] + 2, upd = 1;
      }
    }
    if (upd == 1 && i == n - 1) return puts("No"), 0;
  }
  puts("Yes");
  for (int i = 0; i < m; i++) {
    if (vst[0][a[i]] && vst[1][b[i]])
      printf("%d\n", dis[b[i]] - dis[a[i]]);
    else
      puts("1");
  }
}
