#include <bits/stdc++.h>
using namespace std;
const int P = 1e8 + 1;
int add(int a, int b) {
  if ((a += b) >= P) a -= P;
  return a;
}
int sub(int a, int b) {
  if ((a -= b) < 0) a += P;
  return a;
}
int mul(int a, int b) { return 1ll * a * b % P; }
int kpow(int a, int b) {
  int r = 1;
  for (; b; b >>= 1, a = mul(a, a)) {
    if (b & 1) r = mul(r, a);
  }
  return r;
}
const int N = 1005, M = 5005;
pair<int, int> data[M];
vector<pair<int, int> > V[N];
vector<int> v[N];
int dis[N];
int n, m;
int flag[N], in[N];
int bfs(int s) {
  int vis[N] = {0};
  vis[s] = 1;
  queue<int> Q;
  Q.push(s);
  while (!Q.empty()) {
    int f = Q.front();
    Q.pop();
    for (int i = (0); i < ((int)v[f].size()); i++) {
      int nxt = v[f][i];
      if (!vis[nxt]) {
        Q.push(nxt);
        vis[nxt] = 1;
      }
    }
  }
  if (s == 1)
    for (int i = (1); i < (n + 1); i++) flag[i] = vis[i];
  return vis[n];
}
int spfa() {
  memset(dis, 0x3f, sizeof(dis));
  queue<int> Q;
  dis[1] = 0;
  Q.push(1);
  in[1] = 1;
  while (!Q.empty()) {
    int f = Q.front();
    Q.pop();
    for (int i = (0); i < ((int)V[f].size()); i++) {
      pair<int, int> nxt = V[f][i];
      if (dis[nxt.first] > dis[f] + nxt.second) {
        Q.push(nxt.first);
        in[nxt.first]++;
        if (in[nxt.first] == n + 5) return -1;
        dis[nxt.first] = dis[f] + nxt.second;
      }
    }
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (m); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    data[i] = make_pair(a, b);
  }
  bfs(1);
  for (int i = (2); i < (n + 1); i++) flag[i] &= bfs(i);
  for (int i = (0); i < (m); i++) {
    int a = data[i].first, b = data[i].second;
    if (flag[a] && flag[b]) {
      V[a].push_back(make_pair(b, 2));
      V[b].push_back(make_pair(a, -1));
    }
  }
  int ans = spfa();
  if (ans == -1) {
    puts("No");
    return 0;
  }
  puts("Yes");
  for (int i = (0); i < (m); i++) {
    if (!flag[data[i].first] || !flag[data[i].second])
      puts("1");
    else
      printf("%d\n", dis[data[i].second] - dis[data[i].first]);
  }
  return 0;
}
