#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e3 + 5;
int n, m, from[MAXN], to[MAXN], ok1[MAXN], ok2[MAXN], ok[MAXN], dist[MAXN];
vector<int> g[MAXN], gr[MAXN], graph[MAXN], cost[MAXN];
bool bellman_ford() {
  memset(dist, 0x3f, sizeof dist);
  dist[0] = 0;
  for (int k = 0; k <= n + 5; ++k) {
    for (int i = 0; i <= n; ++i) {
      for (int j = 0; j < graph[i].size(); ++j) {
        int v = graph[i][j];
        if (dist[i] + cost[i][j] < dist[v]) {
          dist[v] = dist[i] + cost[i][j];
          if (k > n + 1) return false;
        }
      }
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> from[i] >> to[i];
    g[from[i]].push_back(to[i]);
    gr[to[i]].push_back(from[i]);
  }
  ok1[1] = true;
  for (int u = 1; u <= n; ++u) {
    for (int i = 0; i < g[u].size(); ++i) {
      int v = g[u][i];
      ok1[v] |= ok1[u];
    }
  }
  ok2[n] = true;
  for (int u = n; u > 0; --u) {
    for (int i = 0; i < gr[u].size(); ++i) {
      int v = gr[u][i];
      ok2[v] |= ok2[u];
    }
  }
  for (int i = 1; i <= n; ++i) ok[i] = ok1[i] && ok2[i];
  for (int i = 0; i < m; ++i) {
    int u = from[i], v = to[i];
    if (!ok[u] || !ok[v]) continue;
    graph[u].push_back(v);
    cost[u].push_back(2);
    graph[v].push_back(u);
    cost[v].push_back(-1);
  }
  for (int i = 1; i <= n; ++i) {
    graph[0].push_back(i);
    cost[0].push_back(0);
  }
  if (bellman_ford()) {
    cout << "Yes" << endl;
    for (int i = 0; i < m; ++i) {
      if (ok[from[i]] && ok[to[i]])
        cout << abs(dist[from[i]] - dist[to[i]]);
      else
        cout << 1;
      cout << endl;
    }
  } else
    cout << "No" << endl;
  return 0;
}
