#include <bits/stdc++.h>
using namespace std;
int first[1005];
bool vis[1005];
int next1[2000009], v[2000009], id[2000009], w[2000009];
int f[1005], cosi[1005], is[1005];
bool vis1[1005];
int d[1005], ans[2000009];
int n, m, tot, cnt;
int inq[1005], in[1005];
struct node {
  int to, id;
};
vector<node> G[1005];
vector<int> V[1005];
void add(int x, int y, int z, int l) {
  v[tot] = y;
  w[tot] = z;
  id[tot] = l;
  next1[tot] = first[x];
  first[x] = tot++;
}
void dfs(int x) {
  vis1[x] = 1;
  for (int i = 0; i < G[x].size(); i++) {
    int v = G[x][i].to;
    if (!vis1[v]) dfs(v);
  }
}
void DFS(int x) {
  vis[x] = 1;
  for (int i = 0; i < G[x].size(); i++) {
    int v = G[x][i].to;
    if (!vis[v]) DFS(v);
  }
}
bool spfa() {
  for (int i = 1; i <= n; i++) d[i] = 1 << 30;
  queue<int> q;
  d[1] = 0;
  q.push(1);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    inq[x] = 0;
    for (int e = first[x]; e != -1; e = next1[e]) {
      if (d[v[e]] > d[x] + w[e]) {
        d[v[e]] = d[x] + w[e];
        if (!inq[v[e]]) {
          in[v[e]]++;
          if (in[v[e]] > n) {
            return 0;
          }
          q.push(v[e]);
          inq[v[e]] = 1;
        }
      }
    }
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(first, -1, sizeof(first));
  tot = 0;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    node tmp;
    tmp.to = y, tmp.id = i;
    G[x].push_back(tmp);
    V[y].push_back(x);
  }
  dfs(1);
  for (int i = 1; i <= n; i++) {
    if (vis1[i]) {
      memset(vis, 0, sizeof(vis));
      DFS(i);
      if (vis[n]) {
        cosi[cnt++] = i;
        is[i] = 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (is[i]) {
      for (int j = 0; j < G[i].size(); j++) {
        int v = G[i][j].to;
        int id = G[i][j].id;
        if (is[v]) {
          add(i, v, 2, id);
          add(v, i, -1, id);
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (is[i]) {
      for (int j = 0; j < V[i].size(); j++) {
        int u = V[i][j];
        if (is[u]) {
          for (int k = j + 1; k < V[i].size(); k++) {
            int v = V[i][k];
            if (is[v]) {
              add(u, v, 1, -1);
              add(v, u, 1, -1);
            }
          }
        }
      }
    }
  }
  if (!spfa())
    printf("No");
  else {
    printf("Yes\n");
    for (int i = 0; i < m; i++) ans[i] = 1;
    for (int i = 1; i <= n; i++) {
      if (is[i]) {
        for (int j = 0; j < G[i].size(); j++) {
          int v = G[i][j].to;
          if (is[v]) {
            int id = G[i][j].id;
            ans[id] = d[v] - d[i];
          }
        }
      }
    }
    for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  }
}
