#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 10;
int last;
int n, m;
string ans;
int dis[maxn];
int cnt[maxn];
int sare[maxn];
int tahe[maxn];
bool mark[maxn];
vector<int> ansvec;
vector<int> adj[maxn];
vector<int> backadj[maxn];
void in();
void solve();
void tabe();
void dfs(int);
void backdfs(int);
void out();
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  in();
  solve();
  out();
}
void in() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    sare[i] = u;
    tahe[i] = v;
    adj[u].push_back(v);
    backadj[v].push_back(u);
  }
}
void solve() {
  dfs(0);
  memset(mark, 0, sizeof mark);
  backdfs(n - 1);
  tabe();
  if (last == n)
    ans = "No";
  else {
    ans = "Yes";
    for (int i = 0; i < m; i++) {
      if (cnt[sare[i]] + cnt[tahe[i]] == 4)
        ansvec.push_back(dis[tahe[i]] - dis[sare[i]]);
      else
        ansvec.push_back(rand() % 2 + 1);
    }
  }
}
void tabe() {
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if (cnt[sare[j]] + cnt[tahe[j]] == 4) {
        if (dis[sare[j]] + 2 < dis[tahe[j]]) {
          last = i;
          dis[tahe[j]] = dis[sare[j]] + 2;
        } else if (dis[tahe[j]] - 1 < dis[sare[j]]) {
          last = i;
          dis[sare[j]] = dis[tahe[j]] - 1;
        }
      }
    }
  }
}
void dfs(int u) {
  cnt[u]++;
  mark[u] = 1;
  for (auto v : adj[u])
    if (!mark[v]) dfs(v);
}
void backdfs(int u) {
  cnt[u]++;
  mark[u] = 1;
  for (auto v : backadj[u])
    if (!mark[v]) backdfs(v);
}
void out() {
  cout << ans << '\n';
  for (auto x : ansvec) cout << x << '\n';
}
