#include <bits/stdc++.h>
using namespace std;
int n, m, cev[6005], reach[6005], ulas[6005];
vector<int> duz[6005], ters[6005];
vector<pair<int, int> > yollar;
inline int fon(int k, int der = 1) {
  if (cev[k] <= der && cev[k]) return reach[k];
  cev[k] = der;
  ulas[k] = 1;
  if (k == n) return reach[k] = 1;
  int bay = 0;
  for (int i = 0; i < (int)duz[k].size(); i++)
    bay = bay | fon(duz[k][i], der + 1);
  reach[k] = bay;
  return bay;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int o1, o2;
    scanf("%d %d", &o1, &o2);
    duz[o1].push_back(o2);
    ters[o2].push_back(o1);
    yollar.push_back(make_pair(o1, o2));
  }
  fon(1, 1);
  for (int qq = 0; qq < n + 2; qq++) {
    int bay = 0;
    for (int i = 0; i < m; i++) {
      int a = yollar[i].first;
      int b = yollar[i].second;
      if (reach[a] && reach[b] && ulas[a] && ulas[b]) {
        if (cev[a] < cev[b] - 2) {
          cev[b] = cev[a] + 2;
          bay = 1;
        }
        if (cev[a] > cev[b] - 1) {
          cev[a] = cev[b] - 1;
          bay = 1;
        }
      }
    }
    if (qq == n + 1 && bay) return printf("No"), 0;
  }
  printf("Yes\n");
  for (int i = 0; i < m; i++) {
    int a = yollar[i].first;
    int b = yollar[i].second;
    int yaz = cev[b] - cev[a];
    if (yaz <= 0 || yaz >= 3) yaz = 1;
    printf("%d\n", yaz);
  }
}
