#include <bits/stdc++.h>
using namespace std;
int n, m, tmp, i, tmp2, tmp3;
int h[10000], dis[10000], h2[10000], x[10000], y[10000], h3[10000];
bool b[10000];
bool bo[10000], bb[10000];
bool p;
struct EDGE {
  int from, to, next, w;
} e[1000000], e2[1000000], e3[1000000];
void add(int a, int b, int c) {
  tmp++;
  e[tmp].from = a;
  e[tmp].to = b;
  e[tmp].next = h[a];
  e[tmp].w = c;
  h[a] = tmp;
}
void add2(int a, int b) {
  tmp2++;
  e2[tmp2].from = a;
  e2[tmp2].to = b;
  e2[tmp2].next = h2[a];
  h2[a] = tmp2;
}
void add3(int a, int b) {
  tmp3++;
  e3[tmp3].from = a;
  e3[tmp3].to = b;
  e3[tmp3].next = h3[a];
  h3[a] = tmp3;
}
void spfa(int k) {
  int s = h[k];
  while (s != 0) {
    int t = e[s].to;
    if (dis[t] < dis[k] + e[s].w) {
      dis[t] = dis[k] + e[s].w;
      if (b[t] == true) {
        p = true;
        return;
      } else {
        b[t] = true;
        spfa(t);
        if (p == true) return;
      }
    }
    s = e[s].next;
  }
  b[k] = false;
}
void dfs(int k) {
  int s = h2[k];
  while (s != 0) {
    int t = e2[s].to;
    if (bo[t] == false) {
      bo[t] = true;
      dfs(t);
    }
    s = e2[s].next;
  }
}
void dfs2(int k) {
  int s = h3[k];
  while (s != 0) {
    int t = e3[s].to;
    if (bb[t] == false) {
      bb[t] = true;
      dfs2(t);
    }
    s = e3[s].next;
  }
}
int main() {
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
    add2(y[i], x[i]);
    add3(x[i], y[i]);
  }
  bo[n] = true;
  dfs(n);
  bb[1] = true;
  dfs2(1);
  for (i = 1; i <= m; i++) {
    if (bo[x[i]] == true && bo[y[i]] == true && bb[x[i]] == true &&
        bb[y[i]] == true) {
      add(x[i], y[i], 1);
      add(y[i], x[i], -2);
    }
  }
  for (i = 1; i <= n; i++) dis[i] = -1000000;
  dis[1] = 0;
  b[1] = true;
  spfa(1);
  if (p == true || dis[n] == -1000000) {
    cout << "No";
    return 0;
  } else {
    cout << "Yes" << endl;
    for (i = 1; i <= m; i++) {
      if (dis[x[i]] == -1000000 || dis[y[i]] == -1000000)
        cout << 1 << endl;
      else
        cout << dis[y[i]] - dis[x[i]] << endl;
    }
  }
  return 0;
}
