#include <bits/stdc++.h>
using namespace std;
const int SIZEN = 1010, SIZEM = 5010;
class Edge {
 public:
  int u, v;
};
int N, M;
Edge E[SIZEM];
bool vis1[SIZEN], vis2[SIZEN];
int dis[SIZEN];
int len[SIZEM];
void DFS1(int x) {
  if (vis1[x]) return;
  vis1[x] = true;
  for (int i = 1; i <= M; i++) {
    if (E[i].u == x) DFS1(E[i].v);
  }
}
void DFS2(int x) {
  if (vis2[x]) return;
  vis2[x] = true;
  for (int i = 1; i <= M; i++) {
    if (E[i].v == x) DFS2(E[i].u);
  }
}
void work(void) {
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      int u = E[j].u, v = E[j].v;
      if (vis1[u] && vis2[v]) {
        dis[v] = min(dis[v], dis[u] + 2);
        dis[u] = min(dis[u], dis[v] - 1);
      }
    }
  }
  for (int i = 1; i <= M; i++) {
    int u = E[i].u, v = E[i].v;
    if (vis1[u] && vis2[v]) {
      if (dis[v] - dis[u] < 1 || dis[v] - dis[u] > 2) {
        printf("No\n");
        return;
      }
      len[i] = dis[v] - dis[u];
    } else
      len[i] = 1;
  }
  printf("Yes\n");
  for (int i = 1; i <= M; i++) printf("%d\n", len[i]);
}
void read(void) {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; i++) scanf("%d%d", &E[i].u, &E[i].v);
}
int main() {
  read();
  DFS1(1);
  DFS2(N);
  work();
  return 0;
}
