#include <bits/stdc++.h>
using namespace std;
struct road {
  int to, val;
} rao[5010];
vector<road> side[1010];
vector<int> edis[1010], zxb[1010];
int minn[1010];
bool used[1010], useful[1010], esa[1010];
bool spfa(int x) {
  used[x] = 1;
  for (int i = 0; i < side[x].size(); i++) {
    int to = side[x][i].to;
    if (!useful[to]) continue;
    if (!esa[to]) continue;
    int val = side[x][i].val;
    if (minn[to] > minn[x] + val) {
      minn[to] = minn[x] + val;
      if (used[to]) return 0;
      if (!spfa(to)) return 0;
    }
  }
  used[x] = 0;
  return 1;
}
void sfd(int x) {
  useful[x] = 1;
  for (int i = 0; i < edis[x].size(); i++) {
    int to = edis[x][i];
    if (useful[to]) continue;
    sfd(to);
  }
}
void dfs(int x) {
  esa[x] = 1;
  for (int i = 0; i < zxb[x].size(); i++) {
    int to = zxb[x][i];
    if (esa[to]) continue;
    dfs(to);
  }
}
int main() {
  ios::sync_with_stdio(0);
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    rao[i].to = a;
    rao[i].val = b;
    zxb[a].push_back(b);
    edis[b].push_back(a);
    side[a].push_back((road){b, -1});
    side[b].push_back((road){a, 2});
  }
  memset(minn, 0x3f, sizeof(minn));
  minn[1] = 1;
  dfs(1);
  sfd(n);
  if (spfa(1)) {
    cout << "Yes\n";
    for (int i = 1; i <= m; i++) {
      int len = minn[rao[i].val] - minn[rao[i].to];
      if (useful[rao[i].val] && esa[rao[i].val] && useful[rao[i].to] &&
          esa[rao[i].to])
        cout << -len << '\n';
      else
        cout << "1\n";
    }
  } else
    cout << "No\n";
}
