#include <bits/stdc++.h>
using namespace std;
int n, m, u[5001], v[5001], d[1001];
bool p[1001], q[1001];
void dfs(int x) {
  if (p[x]) return;
  p[x] = true;
  for (int i = 1; i <= m; i++)
    if (u[i] == x) dfs(v[i]);
}
void dfs2(int x) {
  if (q[x]) return;
  q[x] = true;
  for (int i = 1; i <= m; i++)
    if (v[i] == x) dfs2(u[i]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &u[i], &v[i]);
  dfs(1);
  dfs2(n);
  for (int t = 1; t <= n; t++)
    for (int i = 1; i <= m; i++)
      if (p[u[i]] && q[v[i]]) {
        d[v[i]] = min(d[v[i]], d[u[i]] + 2);
        d[u[i]] = min(d[u[i]], d[v[i]] - 1);
      }
  for (int i = 1; i <= m; i++)
    if (p[u[i]] && q[v[i]] && d[v[i]] - d[u[i]] != 1 && d[v[i]] - d[u[i]] != 2)
      return puts("No"), 0;
  puts("Yes");
  for (int i = 1; i <= m; i++)
    if (d[v[i]] - d[u[i]] == 2)
      puts("2");
    else
      puts("1");
}
