#include <bits/stdc++.h>
using namespace std;
pair<int, int> e[5005], fe[5005], et[5005];
int ans[5005], dis[1005];
bool v[1005], v1[1005];
int main() {
  int n, m, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++)
    scanf("%d%d", &x, &y), et[i] = e[i] = make_pair(x, y),
                           fe[i] = make_pair(y, x);
  sort(e, e + m);
  sort(fe, fe + m);
  memset(dis, 0x3f, sizeof(dis));
  dis[1] = 0;
  v[1] = v1[n] = 1;
  for (int i = 0; i < m; i++) v[e[i].second] |= v[e[i].first];
  for (int i = m - 1; i > -1; i--) v1[fe[i].second] |= v1[fe[i].first];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (v[x = e[j].first] && v1[y = e[j].second]) {
        dis[y] = min(dis[y], dis[x] + 2);
        dis[x] = min(dis[x], dis[y] - 1);
      }
  bool f = 0;
  for (int i = 0; i < m; i++)
    if (v[x = et[i].first] && v1[y = et[i].second]) {
      ans[i] = dis[y] - dis[x];
      if (ans[i] > 2 || ans[i] < 1) f = 1;
    } else
      ans[i] = 1;
  if (f)
    puts("No");
  else {
    puts("Yes");
    for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
