#include <bits/stdc++.h>
using namespace std;
int N, M;
int D[1024], reachS[1024], reachD[1024], SOL[5100];
int indices[1024][1024];
vector<pair<pair<int, int>, int> > edges;
int main() {
  cin >> N >> M;
  int x, y;
  for (int i = 1; i <= M; i++) {
    cin >> x >> y;
    indices[x][y] = i;
    edges.push_back(make_pair(make_pair(y, x), 2));
    edges.push_back(make_pair(make_pair(x, y), -1));
  }
  for (int i = 1; i <= N; i++) {
    edges.push_back(make_pair(make_pair(0, i), 0));
  }
  reachS[1] = 1;
  reachD[N] = 1;
  for (int i = 1; i <= N + 1; i++) {
    for (int j = 0; j < edges.size(); j++) {
      int x = edges[j].first.first;
      int y = edges[j].first.second;
      if (indices[x][y]) {
        if (reachS[x]) reachS[y] = 1;
        if (reachD[y]) reachD[x] = 1;
      }
    }
  }
  for (int i = 1; i <= N; i++) {
    D[i] = 9999999;
  }
  bool updated;
  for (int i = 1; i <= N + 2; i++) {
    updated = false;
    for (int j = 0; j < edges.size(); j++) {
      int x = edges[j].first.first;
      int y = edges[j].first.second;
      if (reachS[x] && reachD[x] && reachS[y] && reachD[y] &&
          D[y] > D[x] + edges[j].second) {
        updated = true;
        D[y] = D[x] + edges[j].second;
      }
    }
  }
  if (updated) {
    cout << "No" << '\n';
    return 0;
  }
  for (int i = 0; i < edges.size(); i++) {
    int x = edges[i].first.first;
    int y = edges[i].first.second;
    if (indices[x][y]) {
      if (reachS[x] && reachD[x] && reachS[y] && reachD[y]) {
        if (D[x] - D[y] == 1) {
          SOL[indices[x][y]] = 1;
        } else if (D[x] - D[y] == 2) {
          SOL[indices[x][y]] = 2;
        }
      } else {
        SOL[indices[x][y]] = 1;
      }
    }
  }
  cout << "Yes" << '\n';
  for (int i = 1; i <= M; i++) {
    cout << SOL[i] << '\n';
  }
  return 0;
}
