#include <bits/stdc++.h>
using namespace std;
int dp[(int)(1e5 + 10)], dp2[(int)(1e5 + 10)], i, j, k, n, m, x, y, z,
    dp3[(int)(1e5 + 10)], dp4[(int)(1e5 + 10)];
vector<pair<int, int> > arr[(int)(1e5 + 10)], rarr[(int)(1e5 + 10)];
vector<pair<pair<int, int>, int> > edge;
int d[(int)(1e5 + 10)];
int f4(int x) {
  if (x == n) return dp4[x] = 0;
  if (dp4[x] != -1) return dp4[x];
  dp4[x] = 1000000007;
  for (int i = 0; i < arr[x].size(); i++)
    dp4[x] = min(f4(arr[x][i].first) + edge[arr[x][i].second].second, dp4[x]);
  return dp4[x];
}
int f3(int x) {
  if (x == 1) return dp3[x] = 0;
  if (dp3[x] != -1) return dp3[x];
  dp3[x] = 1000000007;
  for (int i = 0; i < rarr[x].size(); i++)
    dp3[x] = min(f3(rarr[x][i].first) + edge[rarr[x][i].second].second, dp3[x]);
  return dp3[x];
}
int f2(int x) {
  if (x == n) return dp2[x] = 0;
  if (dp2[x] != -1) return dp2[x];
  dp2[x] = -1000000007;
  for (int i = 0; i < arr[x].size(); i++)
    dp2[x] = max(f2(arr[x][i].first) + edge[arr[x][i].second].second, dp2[x]);
  return dp2[x];
}
int f(int x) {
  if (x == 1) return dp[x] = 0;
  if (dp[x] != -1) return dp[x];
  dp[x] = -1000000007;
  for (int i = 0; i < rarr[x].size(); i++)
    dp[x] = max(f(rarr[x][i].first) + edge[rarr[x][i].second].second, dp[x]);
  return dp[x];
}
int main() {
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    arr[x].push_back(make_pair(y, i - 1));
    rarr[y].push_back(make_pair(x, i - 1));
    edge.push_back(make_pair(make_pair(x, y), 1));
  }
  int first = 0;
  memset(d, 5, sizeof d);
  d[1] = 0;
  memset(dp, -1, sizeof dp);
  memset(dp2, -1, sizeof dp2);
  f(n);
  f2(1);
  for (i = 1; i <= 2 * n; i++)
    for (j = 0; j < m; j++) {
      int a = edge[j].first.first;
      int b = edge[j].first.second;
      if (dp[a] < 0 or dp[b] < 0 or dp2[a] < 0 or dp2[b] < 0) continue;
      d[b] = min(d[a] + 2, d[b]);
      d[a] = min(d[b] - 1, d[a]);
    }
  bool w = 0;
  for (i = 0; i < m; i++) {
    int a = edge[i].first.first;
    int b = edge[i].first.second;
    int t = d[b] - d[a];
    if (t < 1 or t > 2) t = 1;
    edge[i].second = t;
  }
  for (i = 1; i <= n; i++)
    if (d[i] < 0 and (dp[i] >= 0 and dp2[i] >= 0)) w = 1;
  if (w) {
    puts("No");
    return 0;
  }
  puts("Yes");
  for (i = 0; i < m; i++) cout << edge[i].second << '\n';
}
