#include <bits/stdc++.h>
using namespace std;
long long int inf = 100000000ll * +200;
long long int linf = 10000ll * 10000 * 10000 * 10000;
long long int mod = 1e9 + 7;
const int maxn = 5050;
vector<pair<int, pair<int, int> > > Ebl;
vector<pair<int, int> > E;
vector<int> adj[2][maxn];
int d[maxn], mark[2][maxn];
void dfs(int v, int det) {
  mark[det][v] = 1;
  for (int u : adj[det][v]) {
    if (mark[det][u]) continue;
    dfs(u, det);
  }
}
bool belman() {
  for (int i = 0; i < maxn * 2; i++) {
    for (auto P : Ebl) {
      int u = P.second.first;
      int v = P.second.second;
      int w = P.first;
      d[v] = min(d[v], d[u] + w);
    }
  }
  for (auto P : Ebl) {
    int u = P.second.first;
    int v = P.second.second;
    int w = P.first;
    if (d[v] > d[u] + w) {
      return false;
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  fill(d, d + maxn, inf);
  d[0] = 0;
  for (int i = 1; i <= n; i++) {
    Ebl.push_back({0, {0, i}});
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    E.push_back({u, v});
    adj[0][u].push_back(v);
    adj[1][v].push_back(u);
  }
  dfs(1, 0);
  dfs(n, 1);
  for (pair<int, int> P : E) {
    int u = P.first;
    int v = P.second;
    if (mark[0][u] && mark[1][v]) {
      Ebl.push_back({-1, {v, u}});
      Ebl.push_back({2, {u, v}});
    }
  }
  if (belman()) {
    cout << "Yes\n";
    for (pair<int, int> P : E) {
      int u = P.first;
      int v = P.second;
      if (mark[0][u] && mark[1][v]) {
        cout << (d[v] - d[u]) << "\n";
      } else {
        cout << "1\n";
      }
    }
  } else {
    cout << "No";
  }
  return 0;
}
