#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int y, z, next;
} edge[10010];
int n, m;
int tot;
int x[5001];
int y[5001];
int last[1001];
bool can[2][1001];
vector<int> g[2][1001];
void add(int x, int y, int z) {
  edge[++tot].next = last[x];
  edge[tot].y = y;
  edge[tot].z = z;
  last[x] = tot;
}
void dfs(int x, int id) {
  can[id][x] = 1;
  for (int i = 0; i < g[id][x].size(); i++) {
    int y = g[id][x][i];
    if (can[id][y]) continue;
    dfs(y, id);
  }
}
int dis[1001];
bool vi[1001];
bool SPFA() {
  int cnt = 0;
  queue<int> q;
  memset(vi, 0, sizeof(vi));
  for (int i = 1; i <= n; i++) dis[i] = 999999999;
  vi[1] = 1;
  dis[1] = 0;
  q.push(1);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    vi[now] = 0;
    for (int ed = last[now]; ed != 0; ed = edge[ed].next) {
      int y = edge[ed].y;
      if (can[0][y] && can[1][y]) {
        if (dis[y] > dis[now] + edge[ed].z) {
          dis[y] = dis[now] + edge[ed].z;
          if (!vi[y]) {
            vi[y] = 1;
            q.push(y);
            if (y == 1) {
              cnt++;
              if (cnt > n) return 0;
            }
          }
        }
      }
    }
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x[i], &y[i]);
    add(x[i], y[i], 2), add(y[i], x[i], -1);
    g[0][x[i]].push_back(y[i]);
    g[1][y[i]].push_back(x[i]);
  }
  memset(can, 0, sizeof(can));
  dfs(1, 0);
  dfs(n, 1);
  if (SPFA()) {
    printf("Yes\n");
    for (int i = 1; i <= m; i++)
      if (can[0][x[i]] && can[0][y[i]] && can[1][x[i]] && can[1][y[i]])
        printf("%d\n", dis[y[i]] - dis[x[i]]);
      else
        printf("1\n");
  } else
    printf("No\n");
  return 0;
}
