#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005, maxm = 10005;
int n, m, e;
int vis[maxn][2], xx[maxm], yy[maxm], from[maxm], to[maxm], worth[maxm],
    dis[maxn];
vector<int> v[maxn][2];
inline void add(int x, int y, int z) { from[++e] = x, to[e] = y, worth[e] = z; }
void dfs(int x, int t) {
  vis[x][t] = 1;
  for (int i = 0; i < v[x][t].size(); i++) {
    int y = v[x][t][i];
    if (vis[y][t] == 0) dfs(y, t);
  }
}
int Bellman_Ford() {
  int res = 0;
  for (int i = 1; i < n; i++)
    for (int j = 1; j <= e; j++)
      if (dis[to[j]] > dis[from[j]] + worth[j])
        dis[to[j]] = dis[from[j]] + worth[j];
  for (int i = 1; i <= e; i++)
    if (dis[to[i]] > dis[from[i]] + worth[i]) return 1;
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    xx[i] = x, yy[i] = y;
    v[x][0].push_back(y), v[y][1].push_back(x);
  }
  dfs(1, 0), dfs(n, 1);
  for (int i = 1; i <= m; i++)
    if (vis[xx[i]][0] && vis[xx[i]][1] && vis[yy[i]][0] && vis[yy[i]][1])
      add(xx[i], yy[i], 2), add(yy[i], xx[i], -1);
  if (Bellman_Ford()) {
    puts("No");
    return 0;
  }
  puts("Yes");
  for (int i = 1; i <= m; i++) {
    if (vis[xx[i]][0] && vis[xx[i]][1] && vis[yy[i]][0] && vis[yy[i]][1])
      printf("%d\n", dis[yy[i]] - dis[xx[i]]);
    else
      puts("1");
  }
  return 0;
}
