#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 100, M = 30, LG = 30, base = 2;
const int MOD = 1e9 + 7, mod = 1e9 + 9;
const long long INF = 1e9, inf = 1e18;
long long n, m, v, u, x[N], y[N], cnt = 1, dis[N];
bool a[N], b[N];
vector<pair<long long, long long> > g[N], g2[N];
void dfs(int v) {
  for (auto u : g[v])
    if (!a[u.second]) a[u.second] = true, dfs(u.first);
}
void DFS(int v) {
  for (auto u : g2[v])
    if (!b[u.second]) b[u.second] = true, DFS(u.first);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i], x[i]--, y[i]--;
    g[x[i]].push_back({y[i], i}), g2[y[i]].push_back({x[i], i});
  }
  dfs(0), DFS(n - 1);
  for (; cnt && !dis[0];) {
    cnt = 0;
    for (int j = 0; j < m; j++) {
      if (!a[j] || !b[j])
        continue;
      else if (dis[y[j]] <= dis[x[j]]) {
        dis[y[j]] = dis[x[j]] + 1;
        cnt++;
      } else if (dis[x[j]] < dis[y[j]] - 2) {
        dis[x[j]] = dis[y[j]] - 2;
        cnt++;
      }
    }
  }
  if (dis[0] > 0) return cout << "No", 0;
  cout << "Yes"
       << "\n";
  for (int i = 0; i < m; i++) {
    if (!a[i] || !b[i])
      cout << "1"
           << "\n";
    if (a[i] && b[i]) cout << dis[y[i]] - dis[x[i]] << "\n";
  }
  return 0;
}
