#include <bits/stdc++.h>
using namespace std;
int ecnt;
struct Edge {
  int to;
  Edge *next;
} * mat[2][1005], edges[10010];
void link(int k, int x, int to) {
  edges[ecnt].to = to;
  edges[ecnt].next = mat[k][x];
  mat[k][x] = &edges[ecnt++];
}
int n, m, ans[5005];
int dis[1005], mark[1005];
pair<int, int> data[5005];
void fill(int x, int k, int msk) {
  if (mark[x] & msk) return;
  mark[x] |= msk;
  for (Edge *p = mat[k][x]; p; p = p->next) fill(p->to, k, msk);
}
bool solve() {
  fill(1, 0, 1);
  fill(n, 1, 2);
  for (int i = 1; i <= n; i++) dis[i] = 100005;
  dis[1] = 0;
  for (int i = 0; i < n + 10; i++)
    for (int j = 0; j < m; j++) {
      int a = data[j].first, b = data[j].second;
      if (mark[a] != 3 || mark[b] != 3) continue;
      dis[a] = min(dis[a], dis[b] - 1);
      dis[b] = min(dis[b], dis[a] + 2);
    }
  for (int j = 0; j < m; j++) {
    int a = data[j].first, b = data[j].second;
    if (mark[a] != 3 || mark[b] != 3)
      ans[j] = 1;
    else {
      if (dis[b] - dis[a] < 1 || dis[b] - dis[a] > 2) return false;
      ans[j] = dis[b] - dis[a];
    }
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0, x, y; i < m; i++) {
    scanf("%d%d", &x, &y);
    link(0, x, y);
    link(1, y, x);
    data[i].first = x, data[i].second = y;
  }
  if (!solve())
    printf("No\n");
  else {
    printf("Yes\n");
    for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
