#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
int n, m;
vector<int> g[1005], rg[1005];
pair<int, int> es[5005];
int mark[1005], cost[1005];
int ans[5005];
bool solve() {
  for (int i = 0; i < n; ++i) cost[i] = INF;
  cost[0] = 0;
  for (int hoge = 0; hoge < n * 2 + 1; ++hoge)
    for (int i = 0; i < m; ++i)
      if (mark[es[i].second] == 3 && mark[es[i].first] == 3) {
        cost[es[i].second] = min(cost[es[i].second], cost[es[i].first] + 2);
        cost[es[i].first] = min(cost[es[i].first], cost[es[i].second] - 1);
      }
  for (int i = 0; i < m; ++i) {
    if (mark[es[i].first] != 3 || mark[es[i].second] != 3) {
      ans[i] = 1;
      continue;
    }
    int d = cost[es[i].second] - cost[es[i].first];
    if (d != 1 && d != 2) return false;
    ans[i] = d;
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    rg[b].push_back(a);
    es[i] = make_pair(a, b);
  }
  mark[0] = 1;
  for (int i = 0; i < n; ++i)
    if (mark[i] & 1)
      for (int j = 0; j < g[i].size(); ++j) {
        int to = g[i][j];
        mark[to] |= 1;
      }
  mark[n - 1] |= 2;
  for (int i = n - 1; i >= 0; --i)
    if (mark[i] & 2)
      for (int j = 0; j < rg[i].size(); ++j) {
        int to = rg[i][j];
        mark[to] |= 2;
      }
  if (solve()) {
    puts("Yes");
    for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
  } else {
    puts("No");
  }
  return 0;
}
