Flights

LiLand is a country, consisting of n cities. The cities are numbered from 1 to n. The country is well known because it has a very strange transportation system. There are many one-way flights that make it possible to travel between the cities, but the flights are arranged in a way that once you leave a city you will never be able to return to that city again.

Previously each flight took exactly one hour, but recently Lily has become the new manager of transportation system and she wants to change the duration of some flights. Specifically, she wants to change the duration of some flights to exactly 2 hours in such a way that all trips from city 1 to city n take the same time regardless of their path.

Your task is to help Lily to change the duration of flights.

Input

First line of the input contains two integer numbers n and m (2 ≤ n ≤ 1000; 1 ≤ m ≤ 5000) specifying the number of cities and the number of flights.

Each of the next m lines contains two integers a i and b i (1 ≤ a i < b i ≤ n) specifying a one-directional flight from city a i to city b i. It is guaranteed that there exists a way to travel from city number 1 to city number n using the given flights. It is guaranteed that there is no sequence of flights that forms a cyclical path and no two flights are between the same pair of cities.

Output

If it is impossible for Lily to do her task, print “No” (without quotes) on the only line of the output.

Otherwise print “Yes” (without quotes) on the first line of output, then print an integer ans i (1 ≤ ans i ≤ 2) to each of the next m lines being the duration of flights in new transportation system. You should print these numbers in the order that flights are given in the input.

If there are multiple solutions for the input, output any of them.

Examples

input

3 3
1 2
2 3
1 3

output

Yes
1
1
2

input

4 4
1 2
2 3
3 4
1 4

output

No

input

5 6
1 2
2 3
3 5
1 4
4 5
1 3

output

Yes
1
1
1
2
1
2

Solution:

#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>

using namespace std;

const int N = 44444;

int n, m, i, e, j, it;
int ss[N], ff[N], x[N], was[N], d[N];

int main() {
//  freopen("in","r",stdin);
//  freopen("out","w",stdout);
scanf("%d %d", &n, &m);
for (i=1;i<=m;i++) scanf("%d %d", ss+i, ff+i);

  for (i=1;i<=n;i++) was[i] = 0;

  i = 1; e = 1;
  x[1] = 1;
  was[1] |= 1;
  while (i <= e) {
    for (j=1;j<=m;j++)
      if (ss[j] == x[i])
        if (!(was[ff[j]] & 1)) {
          e++;
          x[e] = ff[j];
          was[ff[j]] |= 1;
        }
    i++;
  }

  i = 1; e = 1;
  x[1] = n;
  was[n] |= 2;
  while (i <= e) {
    for (j=1;j<=m;j++)
      if (ff[j] == x[i])
        if (!(was[ss[j]] & 2)) {
          e++;
          x[e] = ss[j];
          was[ss[j]] |= 2;
        }
    i++;
  }

  for (i=1;i<=n;i++) d[i] = (int)1e9;
  d[1] = 0;

  int last = 0;
  for (it=0;it<=3*n;it++) {
    for (i=1;i<=m;i++)
      if (was[ss[i]] == 3 && was[ff[i]] == 3) {
        if (d[ss[i]]+2 < d[ff[i]]) d[ff[i]] = d[ss[i]]+2, last = it;
        if (d[ff[i]]-1 < d[ss[i]]) d[ss[i]] = d[ff[i]]-1, last = it;
      }
  }

  if (last == 3*n) puts("No"); else {
    puts("Yes");
    for (i=1;i<=m;i++)
      if (was[ss[i]] == 3 && was[ff[i]] == 3) printf("%d\n", d[ff[i]]-d[ss[i]]);
      else printf("%d\n", 1);
  }

  return 0;
}