#include <bits/stdc++.h>
using namespace std;
int x[5100], y[5100], dist[1100];
int n, m;
bool vis[1100], v1[1100];
vector<int> mp[1100], re[1100];
void bfs() {
  queue<int> Q;
  memset(vis, false, sizeof(vis));
  Q.push(1);
  vis[1] = true;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = 0; i < mp[x].size(); i++) {
      int y = mp[x][i];
      if (!vis[y]) {
        vis[y] = true;
        Q.push(y);
      }
    }
  }
  memset(v1, false, sizeof(v1));
  Q.push(n);
  v1[n] = true;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = 0; i < re[x].size(); i++) {
      int y = re[x][i];
      if (!v1[y]) {
        v1[y] = true;
        Q.push(y);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x[i], &y[i]);
    mp[x[i]].push_back(y[i]);
    re[y[i]].push_back(x[i]);
  }
  bfs();
  for (int i = 2; i <= n; i++) dist[i] = INT_MAX;
  dist[1] = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (!vis[x[j]] || !vis[y[j]]) continue;
      if (!v1[x[j]] || !v1[y[j]]) continue;
      int xx = x[j], yy = y[j];
      if (dist[xx] != INT_MAX)
        if (dist[xx] + 2 < dist[yy]) dist[yy] = dist[xx] + 2;
      if (dist[yy] != INT_MAX)
        if (dist[yy] - 1 < dist[xx]) dist[xx] = dist[yy] - 1;
    }
  }
  bool flag = true;
  for (int j = 0; j < m; j++) {
    if (!vis[x[j]] || !vis[y[j]]) continue;
    if (!v1[x[j]] || !v1[y[j]]) continue;
    int xx = x[j], yy = y[j];
    if (dist[xx] != INT_MAX)
      if (dist[xx] + 2 < dist[yy]) {
        flag = false;
        break;
      }
    if (dist[yy] != INT_MAX)
      if (dist[yy] - 1 < dist[xx]) {
        flag = false;
        break;
      }
  }
  if (flag) {
    printf("Yes\n");
    for (int i = 0; i < m; i++) {
      int tmp = dist[y[i]] - dist[x[i]];
      if (tmp != 1 && tmp != 2)
        printf("1\n");
      else
        printf("%d\n", tmp);
    }
  } else {
    printf("No\n");
  }
  return 0;
}
