#include <bits/stdc++.h>
using namespace std;
int V, E;
int a[5010], b[5010];
bool graph[1010][1010];
bool s[1010], t[1010];
int x[1010];
bool func(void) {
  int i, j;
  for ((i) = 0; (i) < (int)(V); (i)++) x[i] = (1 << 29);
  x[0] = 0;
  for ((i) = 0; (i) < (int)(V); (i)++)
    for ((j) = 0; (j) < (int)(E); (j)++)
      if (s[a[j]] && t[b[j]]) {
        x[b[j]] = min(x[b[j]], x[a[j]] + 2);
        x[a[j]] = min(x[a[j]], x[b[j]] - 1);
      }
  for ((j) = 0; (j) < (int)(E); (j)++)
    if (s[a[j]] && t[b[j]]) {
      int d = x[b[j]] - x[a[j]];
      if (d != 1 && d != 2) return false;
    }
  return true;
}
int main(void) {
  int i, j;
  cin >> V >> E;
  for ((i) = 0; (i) < (int)(E); (i)++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  for ((i) = 0; (i) < (int)(E); (i)++) graph[a[i]][b[i]] = true;
  s[0] = true;
  for (i = 1; i < V; i++)
    for ((j) = 0; (j) < (int)(i); (j)++)
      if (graph[j][i] && s[j]) s[i] = true;
  t[V - 1] = true;
  for (i = V - 2; i >= 0; i--)
    for (j = i + 1; j < V; j++)
      if (graph[i][j] && t[j]) t[i] = true;
  bool ans = func();
  if (!ans) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for ((i) = 0; (i) < (int)(E); (i)++) {
      if (!s[a[i]] || !t[b[i]]) {
        cout << 1 << endl;
      } else {
        cout << x[b[i]] - x[a[i]] << endl;
      }
    }
  }
  return 0;
}
