#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 5;
int N, M;
bool PC;
int u[maxn], v[maxn], vis[maxn], vis2[maxn], dis[maxn], flag[maxn];
vector<int> G[maxn], W[maxn], G2[maxn];
void Dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i], w = W[u][i];
    if (dis[v] > dis[u] + w) {
      if (vis[v] || PC) {
        PC = 1;
        return;
      }
      dis[v] = dis[u] + w;
      Dfs(v);
    }
  }
  vis[u] = 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    cin >> u[i] >> v[i];
    G[u[i]].push_back(v[i]);
    G2[v[i]].push_back(u[i]);
  }
  queue<int> q;
  q.push(1);
  vis[1] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (!vis[v]) {
        vis[v] = 1;
        q.push(v);
      }
    }
  }
  q.push(N);
  vis2[N] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < G2[u].size(); i++) {
      int v = G2[u][i];
      if (!vis2[v]) {
        vis2[v] = 1;
        q.push(v);
      }
    }
  }
  if (!vis[N]) {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 1; i <= N; i++)
    if (vis[i] && vis2[i]) flag[i] = 1;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= N; i++) G[i].clear();
  for (int i = 1; i <= M; i++) {
    if (!(flag[u[i]] && flag[v[i]])) continue;
    G[v[i]].push_back(u[i]);
    W[v[i]].push_back(-1);
    G[u[i]].push_back(v[i]);
    W[u[i]].push_back(2);
  }
  for (int i = 1; i <= N; i++) {
    Dfs(i);
    if (PC) break;
  }
  if (PC) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  for (int i = 1; i <= M; i++)
    cout << (flag[v[i]] && flag[u[i]] ? dis[v[i]] - dis[u[i]] : 1) << endl;
  return 0;
}
