#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void in(T &x) {
  x = 0;
  short f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
  x *= f;
}
template <class T>
inline void out(T x, const char c = '\n') {
  static short st[30];
  short m = 0;
  if (x < 0) putchar('-'), x = -x;
  do st[++m] = x % 10, x /= 10;
  while (x);
  while (m) putchar(st[m--] | '0');
  putchar(c);
}
template <class T, class... Args>
inline void in(T &x, Args &...args) {
  in(x);
  in(args...);
}
template <class T, class... Args>
inline void out(const T &x, const Args &...args) {
  out(x, ' ');
  out(args...);
}
template <class T>
inline void prt(T a[], int n) {
  for (register int i = 0; i < n; ++i) out(a[i], ' ');
  putchar('\n');
}
template <class T>
inline void clr(T a[], int n) {
  memset(a, 0, sizeof(T) * n);
}
template <class T>
inline void clr(T *a, T *b) {
  memset(a, 0, sizeof(T) * (b - a));
}
template <class T>
inline bool ckmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline bool ckmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
namespace MOD_CALC {
const int md = 998244353;
inline int add(const int a, const int b) {
  return a + b >= md ? a + b - md : a + b;
}
inline int sub(const int a, const int b) {
  return a - b < 0 ? a - b + md : a - b;
}
inline int mul(const int a, const int b) { return (long long)a * b % md; }
inline void inc(int &a, const int b) { (a += b) >= md ? a -= md : 0; }
inline void dec(int &a, const int b) { (a -= b) < 0 ? a += md : 0; }
inline int qpow(int a, int b) {
  int r = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1) r = mul(r, a);
  return r;
}
inline int mdinv(const int a) { return qpow(a, md - 2); }
}  // namespace MOD_CALC
using namespace MOD_CALC;
namespace i207M {
int n, m;
vector<int> E[1005], fE[1005];
int vis[1005];
void dfs(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  for (const auto &v : E[x]) dfs(v);
}
void efs(int x) {
  if (vis[x] == 1) {
    vis[x] = 2;
    for (const auto &v : fE[x]) efs(v);
  }
}
int d[1005];
bool work() {
  bool res = 0;
  for (register int x = 1; x <= n; ++x)
    if (vis[x] == 2)
      for (const auto &v : E[x]) {
        if (vis[v] != 2) continue;
        res |= ckmax(d[v], d[x] + 1);
        res |= ckmax(d[x], d[v] - 2);
      }
  return res;
}
int ide[1005][1005];
int ans[1005 * 5];
signed main() {
  in(n, m);
  for (register int i = 1, a, b; i <= m; ++i) {
    in(a, b);
    E[a].push_back(b), fE[b].push_back(a);
    ide[a][b] = i, ans[i] = 1;
  }
  dfs(1);
  efs(n);
  while (work() && d[1] == 0)
    ;
  if (d[1] != 0) {
    puts("No");
    return 0;
  }
  for (register int x = 1; x <= n; ++x)
    if (vis[x] == 2)
      for (const auto &v : E[x]) {
        if (vis[v] != 2) continue;
        ans[ide[x][v]] = d[v] - d[x];
      }
  puts("Yes");
  for (register int i = 1; i <= m; ++i) out(ans[i]);
  return 0;
}
}  // namespace i207M
signed main() {
  i207M::main();
  return 0;
}
