#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, cev[1005], reach[1005], ulas[1005];
vector<int> duz[1005];
vector<pair<int, int> > yol;
int fon(int node, int der) {
  if (cev[node] <= der && cev[node]) return reach[node];
  cev[node] = der;
  ulas[node] = 1;
  if (node == n) return reach[node] = 1;
  int bay = 0;
  for (int i = 0; i < (int)duz[node].size(); i++) {
    int go = duz[node][i];
    bay = bay | fon(go, der + 1);
  }
  reach[node] = bay;
  return bay;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    duz[x].push_back(y);
    yol.push_back(make_pair(x, y));
  }
  fon(1, 1);
  for (int i = 1; i <= n + 1; i++) {
    int bay = 0;
    for (int j = 0; j < m; j++) {
      int seh1 = yol[j].first;
      int seh2 = yol[j].second;
      if (ulas[seh1] == 1 && ulas[seh2] == 1 && reach[seh1] == 1 &&
          reach[seh2] == 1) {
        if (cev[seh1] + 2 < cev[seh2]) {
          cev[seh2] = cev[seh1] + 2;
          bay = 1;
        }
        if (cev[seh1] >= cev[seh2]) {
          cev[seh1] = cev[seh2] - 1;
          bay = 1;
        }
      }
    }
    if (i == n + 1 && bay == 1) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  for (int i = 0; i < m; i++) {
    int seh1 = yol[i].first;
    int seh2 = yol[i].second;
    int gg = cev[seh2] - cev[seh1];
    if (gg < 1 || gg >= 3) gg = 1;
    printf("%d\n", gg);
  }
  return 0;
}
