#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  register char c = getchar();
  bool f = 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') c = getchar(), f = 1;
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
  x = f ? -x : x;
  return;
}
template <class T>
inline void write(T x) {
  if (!x) {
    putchar(48);
    return;
  }
  if (x < 0) x = -x, putchar('-');
  int len = -1, z[20];
  while (x > 0) z[++len] = x % 10, x /= 10;
  for (register int i = len; i >= 0; i--) putchar(z[i] + 48);
  return;
}
const int N = 10010;
struct node {
  int to, nxt, w;
} g[N * 10];
int lst[N], gl;
void add(int x, int y, int z) {
  g[++gl] = (node){y, lst[x], z};
  lst[x] = gl;
}
vector<pair<int, int> > E[N];
vector<int> E2[N];
bool vis1[N], visn[N];
void dfs(int x) {
  vis1[x] = 1;
  for (int i = 0; i < E[x].size(); i++) {
    int v = E[x][i].first;
    if (!vis1[v]) dfs(v);
  }
}
void dfs2(int x) {
  visn[x] = 1;
  for (int i = 0; i < E2[x].size(); i++) {
    int v = E2[x][i];
    if (!visn[v]) dfs2(v);
  }
}
int cnt[N], dis[N], n, m;
queue<int> q;
bool vis[N];
bool spfa() {
  q.push(1);
  memset(dis, 127 / 3, sizeof(dis));
  dis[1] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = lst[u]; i; i = g[i].nxt) {
      int v = g[i].to;
      if (dis[v] > dis[u] + g[i].w) {
        dis[v] = dis[u] + g[i].w;
        if ((++cnt[v]) == n) return 0;
        if (!vis[v]) {
          vis[v] = 1;
          q.push(v);
        }
      }
    }
  }
  return 1;
}
int ans[N];
int main() {
  read(n), read(m);
  for (int i = 1, x, y; i <= m; i++) {
    read(x), read(y);
    E[x].push_back(make_pair(y, i));
    E2[y].push_back(x);
  }
  dfs(1);
  dfs2(n);
  for (int u = 1; u <= n; u++)
    for (auto v : E[u])
      if (vis1[u] && visn[v.first]) {
        add(v.first, u, 2);
        add(u, v.first, -1);
      }
  if (!spfa())
    puts("No");
  else {
    puts("Yes");
    int flg = 0;
    for (int u = 1; u <= n; u++)
      for (auto v : E[u])
        if (vis1[u] && visn[v.first])
          ans[v.second] = dis[u] - dis[v.first];
        else
          ans[v.second] = 1;
    for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
