#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, next;
} e1[5005], e2[5005];
struct EDGE {
  int to, next, va;
} e[5005 << 1];
int head1[1005], head2[1005], head[1005], cnt1, cnt2, cnt, Count1[1005],
    Count2[1005], dis[1005], vis[1005], num[1005];
int n, m;
int x[5005], y[5005];
queue<int> Q1;
queue<int> Q2;
queue<int> q;
void add1(int a, int b) {
  e1[++cnt1] = {b, head1[a]};
  head1[a] = cnt1;
}
void add2(int a, int b) {
  e2[++cnt2] = {b, head2[a]};
  head2[a] = cnt2;
}
void add(int a, int b, int c) {
  e[++cnt] = {b, head[a], c};
  head[a] = cnt;
}
void dfs1(int s) {
  Q1.push(s);
  while (!Q1.empty()) {
    int u = Q1.front();
    Q1.pop();
    if (Count1[u]) continue;
    Count1[u] = 1;
    for (int i = head1[u]; i; i = e1[i].next) {
      int v = e1[i].to;
      if (!Count1[v]) Q1.push(v);
    }
  }
}
void dfs2(int s) {
  Q2.push(s);
  while (!Q2.empty()) {
    int u = Q2.front();
    Q2.pop();
    if (Count2[u]) continue;
    Count2[u] = 1;
    for (int i = head2[u]; i; i = e2[i].next) {
      int v = e2[i].to;
      if (!Count2[v]) Q2.push(v);
    }
  }
}
void spfa() {
  memset(dis, -63, sizeof(dis));
  dis[1] = 0;
  q.push(1);
  vis[1] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to, w = e[i].va;
      if (dis[v] < dis[u] + w) {
        dis[v] = dis[u] + w;
        if (!vis[v]) {
          q.push(v);
          vis[v] = 1;
          num[v]++;
        }
      }
    }
    if (num[u] >= n) {
      cout << "No" << endl;
      exit(0);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
    add1(x[i], y[i]);
    add2(y[i], x[i]);
  }
  dfs1(1);
  dfs2(n);
  for (int i = 1; i <= m; i++) {
    int u = x[i], v = y[i];
    if (Count1[u] && Count2[v] && Count1[v] && Count2[u]) {
      add(u, v, 1);
      add(v, u, -2);
    }
  }
  spfa();
  cout << "Yes" << endl;
  for (int i = 1; i <= m; i++) {
    int u = x[i], v = y[i];
    if (Count1[u] && Count2[v] && Count1[v] && Count2[u]) {
      cout << dis[v] - dis[u] << endl;
    } else
      cout << "1" << endl;
  }
  return 0;
}
