#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &t) {
  t = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    t = (t << 3) + (t << 1) + c - '0';
    c = getchar();
  }
  t *= f;
}
template <typename T, typename... Args>
inline void read(T &t, Args &...args) {
  read(t);
  read(args...);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int n, m;
pair<int, int> Edge[5005];
int toop = 1, to[5005 << 1], nxt[5005 << 1], wei[5005 << 1], tim[1005],
    vis[1005], dis[1005], head[1005];
void Add_Edge(int u, int v, int w) {
  to[++toop] = v, wei[toop] = w, nxt[toop] = head[u], head[u] = toop;
}
void Spfa() {
  queue<int> q;
  while (!q.empty()) q.pop();
  memset(vis, 0, sizeof(vis));
  memset(dis, 0x3f, sizeof(dis));
  q.push(1), vis[1] = 1, dis[1] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0, tim[u]++;
    if (tim[u] > n) {
      puts("No");
      exit(0);
    }
    for (register int i = head[u]; i; i = nxt[i]) {
      int v = to[i], w = wei[i];
      if (dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        if (!vis[v]) vis[v] = 1, q.push(v);
      }
    }
  }
}
vector<int> G[2][1005];
int ans[1005], vis1[1005];
void dfs(int u, int ty) {
  vis1[u] |= 1 << ty;
  for (int v : G[ty][u])
    if (!(vis1[v] & (1 << ty))) dfs(v, ty);
}
signed main() {
  read(n, m);
  for (register int i = 1, u, v; i <= m; ++i)
    read(u, v), Edge[i] = make_pair(u, v), G[0][u].push_back(v),
                G[1][v].push_back(u);
  dfs(1, 0), dfs(n, 1);
  for (register int i = 1, u, v; i <= m; ++i) {
    u = Edge[i].first, v = Edge[i].second;
    if (vis1[u] == 3 && vis1[v] == 3) Add_Edge(u, v, 2), Add_Edge(v, u, -1);
  }
  Spfa();
  puts("Yes");
  for (register int i = 1; i <= m; ++i) {
    int u = Edge[i].first, v = Edge[i].second;
    if (vis1[u] == 3 && vis1[v] == 3)
      write(dis[v] - dis[u]), putchar('\n');
    else
      puts("1");
  }
  return 0;
}
