#include <bits/stdc++.h>
using namespace std;
long long n, m, vf[5010];
bool ds[5010], dt[5010];
vector<long long> vt[5010], bk[5010];
vector<pair<long long, long long> > ed;
void dfs(long long x) {
  long long i;
  ds[x] = true;
  for (i = 0; i < vt[x].size(); i++) {
    if (!ds[vt[x][i]]) {
      dfs(vt[x][i]);
    }
  }
  return;
}
void dfs2(long long x) {
  long long i;
  dt[x] = true;
  for (i = 0; i < bk[x].size(); i++) {
    if (!dt[bk[x][i]]) {
      dfs2(bk[x][i]);
    }
  }
  return;
}
int main() {
  long long i, j, x, y;
  scanf("%lld%lld", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%lld%lld", &x, &y);
    x--;
    y--;
    ed.push_back(make_pair(x, y));
    vt[x].push_back(y);
    bk[y].push_back(x);
  }
  memset(ds, false, sizeof(ds));
  dfs(0);
  memset(dt, false, sizeof(dt));
  dfs2(n - 1);
  memset(vf, 127, sizeof(vf));
  vf[0] = 0;
  for (j = 0; j <= n; j++) {
    for (i = 0; i < ed.size(); i++) {
      if (ds[ed[i].first] && dt[ed[i].second]) {
        x = vf[ed[i].second];
        y = vf[ed[i].first];
        vf[ed[i].second] = min(vf[ed[i].second], y + 2);
        vf[ed[i].first] = min(vf[ed[i].first], x - 1);
      }
    }
  }
  for (i = 0; i < m; i++) {
    if (ds[ed[i].first] && dt[ed[i].second]) {
      if (abs(vf[ed[i].second] - vf[ed[i].first]) != 1 &&
          abs(vf[ed[i].second] - vf[ed[i].first]) != 2) {
        puts("No");
        return 0;
      }
    }
  }
  puts("Yes");
  for (i = 0; i < ed.size(); i++) {
    if ((!ds[ed[i].first]) || (!dt[ed[i].second])) {
      puts("1");
    } else {
      printf("%lld\n", abs(vf[ed[i].second] - vf[ed[i].first]));
    }
  }
  return 0;
}
