#include <bits/stdc++.h>
using namespace std;
const int MAXM = 7010;
const int MAXN = 5010;
int n, m, i, j;
bool vis[2][MAXM];
int dis[MAXM];
int st[MAXM], ed[MAXM], ans[MAXM];
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &st[i], &ed[i]);
  }
}
void dfs1(int u) {
  if (vis[1][u]) return;
  vis[1][u] = true;
  for (int i = 0; i < m; ++i)
    if (st[i] == u) dfs1(ed[i]);
}
void dfs0(int u) {
  if (vis[0][u]) return;
  vis[0][u] = true;
  for (int i = 0; i < m; ++i)
    if (ed[i] == u) dfs0(st[i]);
}
int main() {
  init();
  dfs1(1);
  dfs0(n);
  bool flag = false;
  for (int i = 1; i <= n; ++i) {
    flag = false;
    for (int j = 0; j < m; ++j) {
      if (vis[1][st[j]] && vis[0][ed[j]]) {
        if (dis[st[j]] > dis[ed[j]] - 1) {
          dis[st[j]] = dis[ed[j]] - 1;
          flag = true;
        }
        if (dis[ed[j]] > dis[st[j]] + 2) {
          dis[ed[j]] = dis[st[j]] + 2;
          flag = true;
        }
      }
    }
    if (flag && i == n) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  for (int i = 0; i < m; ++i) {
    if (vis[1][st[i]] && vis[0][ed[i]]) {
      printf("%d\n", dis[ed[i]] - dis[st[i]]);
    } else
      printf("1\n");
  }
  return 0;
}
