#include <bits/stdc++.h>
using namespace std;
vector<int> d[10000];
int mark[10000];
int c = 0;
void dfs(int x) {
  if (mark[x] == 2) return;
  if (mark[x] == 1) {
    c = 1;
    return;
  }
  mark[x] = 1;
  for (int i = 0; i < d[x].size(); i++) {
    dfs(d[x][i]);
  }
  mark[x] = 2;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cout << setprecision(10);
  int n, m;
  cin >> n >> m;
  int a[m];
  int b[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    d[a[i]].push_back(b[i]);
  }
  for (int i = 0; i < n; i++) {
    if (mark[i] == 0) dfs(i);
  }
  if (c == 0) {
    cout << 1 << endl;
    for (int i = 0; i < m; i++) cout << 1 << " ";
  } else {
    cout << 2 << endl;
    for (int i = 0; i < m; i++) {
      if (a[i] < b[i])
        cout << 1 << " ";
      else
        cout << 2 << " ";
    }
  }
}
