#include <bits/stdc++.h>
using namespace std;
const unsigned long long seed = 13331;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 1e5 + 7;
const int maxm = 8e6 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
struct Edge {
  int v, w;
};
vector<Edge> edge[maxn];
vector<int> mp[maxn];
int n, m, vis[maxn], p[maxn], dis[maxn], a[maxn], b[maxn], num[maxn];
int dfs(int x) {
  if (vis[x]) return p[x];
  vis[x] = 1;
  if (x == n) return p[x] = 1;
  for (auto v : mp[x])
    if (dfs(v)) p[x] = 1;
  return p[x];
}
int cnt[maxn];
int spfa() {
  for (int i = 1; i <= n; i++) dis[i] = INF, num[i] = 0, vis[i] = 0, cnt[i] = 0;
  queue<int> q;
  q.push(1);
  dis[1] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = 0; i < edge[u].size(); i++) {
      int v = edge[u][i].v, w = edge[u][i].w;
      if (dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        cnt[v] = cnt[u] + 1;
        if (cnt[v] > n) return 1;
        if (!vis[v]) {
          q.push(v), vis[v] = 1;
          num[v]++;
          if (num[v] > n) return 1;
        }
      }
    }
  }
  return 0;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0, u, v; i < m; ++i) {
    scanf("%d %d", &u, &v);
    a[i] = u, b[i] = v;
    mp[u].push_back(v);
  }
  dfs(1);
  for (int i = 1; i <= n; i++) {
    if (!p[i]) continue;
    for (auto v : mp[i]) {
      if (!p[v]) continue;
      edge[i].push_back({v, 2});
      edge[v].push_back({i, -1});
    }
  }
  if (spfa())
    return 0 * printf("No\n");
  else {
    printf("Yes\n");
    for (int i = 0; i < m; i++) {
      if (!p[a[i]] || !p[b[i]])
        printf("1\n");
      else
        printf("%d\n", dis[b[i]] - dis[a[i]]);
    }
  }
  return 0;
}
