#include <bits/stdc++.h>
using namespace std;
struct ed {
  int u, v;
} e[5100];
int n, m;
int go1[5100];
int go2[5100];
void dfs1(int x) {
  if (go1[x]) return;
  go1[x] = 1;
  for (int i = (1); i <= (m); i++)
    if (e[i].u == x) dfs1(e[i].v);
}
void dfs2(int x) {
  if (go2[x]) return;
  go2[x] = 1;
  for (int i = (1); i <= (m); i++)
    if (e[i].v == x) dfs2(e[i].u);
}
int dis[5100];
int main() {
  scanf("%d%d", &n, &m);
  memset(dis, 0x00, sizeof dis);
  for (int i = (1); i <= (m); i++) scanf("%d%d", &e[i].u, &e[i].v);
  dfs1(1);
  dfs2(n);
  for (int i = (0); i <= (n + m); i++)
    for (int j = (1); j <= (m); j++)
      if (go1[e[j].u] && go2[e[j].v]) {
        dis[e[j].v] = min(dis[e[j].u] + 2, dis[e[j].v]);
        dis[e[j].u] = min(dis[e[j].v] - 1, dis[e[j].u]);
      }
  for (int i = (1); i <= (m); i++)
    if (go1[e[i].u] && go2[e[i].v])
      if (dis[e[i].v] - dis[e[i].u] < 1 || dis[e[i].v] - dis[e[i].u] > 2) {
        printf("No\n");
        return 0;
      }
  printf("Yes\n");
  for (int i = (1); i <= (m); i++)
    printf("%d\n", max(1, min(2, dis[e[i].v] - dis[e[i].u])));
  return 0;
}
