#include <bits/stdc++.h>
using namespace std;
int N, M, u[20001], v[20001], fst[1001], cnt, to[20001], len[20001], nxt[20001],
    dis[1001], tot[1001];
bool vis[1001][2], in[1001];
void add(int u, int v, int l) {
  to[++cnt] = v, len[cnt] = l, nxt[cnt] = fst[u], fst[u] = cnt;
}
int main() {
  cin >> N >> M;
  for (int i = 1; i <= M; i++) cin >> u[i] >> v[i], add(u[i], v[i], 0);
  queue<int> q;
  q.push(1);
  vis[1][0] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = fst[u]; i; i = nxt[i])
      if (!vis[to[i]][0]) vis[to[i]][0] = 1, q.push(to[i]);
  }
  memset(fst, 0, sizeof(fst));
  cnt = 0;
  for (int i = 1; i <= M; i++) add(v[i], u[i], 0);
  q.push(N);
  vis[N][1] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = fst[u]; i; i = nxt[i])
      if (!vis[to[i]][1]) vis[to[i]][1] = 1, q.push(to[i]);
  }
  memset(fst, 0, sizeof(fst));
  cnt = 0;
  for (int i = 1; i <= N; i++) add(0, i, 0);
  for (int i = 1; i <= M; i++)
    if (vis[u[i]][0] && vis[v[i]][1]) add(u[i], v[i], 2), add(v[i], u[i], -1);
  memset(dis, 0x3f, sizeof(dis));
  dis[0] = 0;
  q.push(0);
  in[0] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    in[u] = 0;
    tot[u]++;
    if (tot[u] > N) {
      cout << "No\n";
      return 0;
    }
    for (int i = fst[u]; i; i = nxt[i])
      if (dis[to[i]] > dis[u] + len[i])
        dis[to[i]] = dis[u] + len[i], !in[to[i]] ? q.push(to[i]), 0 : 0;
  }
  cout << "Yes\n";
  for (int i = 1; i <= M; i++)
    cout << (vis[u[i]][0] && vis[v[i]][1] ? dis[v[i]] - dis[u[i]] : 1) << endl;
  return 0;
}
