#include <bits/stdc++.h>
using namespace std;
long long n, m, x[5005], y[5005];
long long ee, h[5005], nex[5005], to[5005];
long long col[5005], du[5005];
void addedge(long long x, long long y) {
  nex[++ee] = h[x];
  to[ee] = y;
  h[x] = ee;
}
bool topo() {
  queue<long long> q;
  for (long long i = 1; i <= n; i++)
    if (du[i] == 0) q.push(i);
  long long s = 0;
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    s++;
    for (long long i = h[x]; i; i = nex[i])
      if ((--du[to[i]]) == 0) q.push(to[i]);
  }
  return s == n;
}
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= m && cin >> x[i] >> y[i]; i++)
    addedge(x[i], y[i]), du[y[i]]++;
  if (topo()) {
    cout << 1 << endl;
    for (long long i = 1; i <= m; i++) cout << 1 << ' ';
  } else {
    cout << 2 << endl;
    for (long long i = 1; i <= m; i++)
      if (x[i] > y[i])
        cout << 1 << ' ';
      else
        cout << 2 << ' ';
  }
  return puts(""), 0;
}
