#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005, inf = 2e9;
int V[maxn], U[maxn], d[maxn];
bitset<maxn> f1, f2;
vector<int> adj[maxn], r[maxn];
vector<pair<int, int> > g[maxn];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    adj[v].push_back(u);
    r[u].push_back(v);
    V[i] = v;
    U[i] = u;
  }
  queue<int> Q;
  f1[0] = 1;
  Q.push(0);
  while (Q.size()) {
    int v = Q.front();
    Q.pop();
    for (auto u : adj[v]) {
      if (!f1[u]) {
        f1[u] = 1;
        Q.push(u);
      }
    }
  }
  f2[n - 1] = 1;
  Q.push(n - 1);
  while (Q.size()) {
    int v = Q.front();
    Q.pop();
    for (auto u : r[v]) {
      if (!f2[u]) {
        f2[u] = 1;
        Q.push(u);
      }
    }
  }
  for (int v = 0; v < n; v++) {
    for (auto u : adj[v]) {
      if (f1[v] && f2[u]) {
        g[v].push_back(pair<int, int>(u, +2));
        g[u].push_back(pair<int, int>(v, -1));
      }
    }
  }
  fill(d, d + n, inf);
  d[0] = 0;
  for (int i = 0; i <= n + 1; i++) {
    for (int v = 0; v < n; v++) {
      for (auto P : g[v]) {
        int u = P.first, w = P.second;
        if (d[u] > d[v] + w) {
          d[u] = d[v] + w;
          if (i >= n) {
            cout << "No";
            return 0;
          }
        }
      }
    }
  }
  cout << "Yes\n";
  for (int i = 0; i < m; i++) {
    if (d[V[i]] + 1 == d[U[i]])
      cout << "1\n";
    else
      cout << "2\n";
  }
}
