#include <bits/stdc++.h>
using namespace std;
vector<int> pgo[1010], rgo[1010];
bool pvis[1010], rvis[1010];
void pdfs(int vr) {
  if (pvis[vr]) return;
  pvis[vr] = true;
  for (int i = 0; i < ((int)(pgo[vr]).size()); ++i) pdfs(pgo[vr][i]);
}
void rdfs(int vr) {
  if (rvis[vr]) return;
  rvis[vr] = true;
  for (int i = 0; i < ((int)(rgo[vr]).size()); ++i) rdfs(rgo[vr][i]);
}
int N, M;
vector<pair<int, int> > edg;
map<pair<int, int>, int> ans;
vector<int> le, ri, w;
int sp[1010];
void paths() {
  for (int i = 0; i < N; ++i) sp[i] = 1000000000;
  sp[N - 1] = 0;
  for (int iter = 0; iter < N; ++iter) {
    for (int i = 0; i < ((int)(le).size()); ++i)
      (sp[ri[i]]) = min((sp[ri[i]]), (sp[le[i]] + w[i]));
  }
  int val = sp[N - 1];
  for (int i = 0; i < N; ++i) sp[i] -= val;
}
bool OK = true;
int sol[1010];
bool fix[1010];
vector<int> fo[1010], wgt[1010];
int dfs(int vr) {
  if (fix[vr]) return sol[vr];
  fix[vr] = true;
  sol[vr] = 1000000000;
  for (int i = 0; i < ((int)(fo[vr]).size()); ++i)
    (sol[vr]) = min((sol[vr]), (dfs(fo[vr][i]) + wgt[vr][i]));
  for (int i = 0; i < ((int)(fo[vr]).size()); ++i) {
    if (dfs(fo[vr][i]) == 1000000000) continue;
    if (sol[vr] != dfs(fo[vr][i]) + wgt[vr][i]) OK = false;
  }
  return sol[vr];
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    edg.push_back(make_pair(a, b));
    ans[make_pair(a, b)] = 1;
    pgo[a].push_back(b);
    rgo[b].push_back(a);
  }
  pdfs(0);
  rdfs(N - 1);
  for (int i = 0; i < M; ++i) {
    int a = edg[i].first, b = edg[i].second;
    if (!pvis[a] || !rvis[a]) continue;
    if (!pvis[b] || !rvis[b]) continue;
    le.push_back(b);
    ri.push_back(a);
    w.push_back(2);
    le.push_back(a);
    ri.push_back(b);
    w.push_back(-1);
  }
  paths();
  for (int i = 0; i < ((int)(edg).size()); ++i) {
    int a = edg[i].first, b = edg[i].second;
    if (sp[a] == 1000000000 || sp[b] == 1000000000) continue;
    int w = sp[a] - sp[b];
    ans[make_pair(a, b)] = w;
    if (w < 1 || w > 2) {
      OK = false;
      break;
    }
  }
  for (map<pair<int, int>, int>::iterator it = ans.begin(); it != ans.end();
       ++it) {
    fo[it->first.first].push_back(it->first.second);
    wgt[it->first.first].push_back(it->second);
  }
  fix[N - 1] = true;
  sol[N - 1] = 0;
  dfs(0);
  if (!OK)
    puts("No");
  else {
    puts("Yes");
    for (int i = 0; i < ((int)(edg).size()); ++i) printf("%d\n", ans[edg[i]]);
  }
  return 0;
}
