#include <bits/stdc++.h>
using namespace std;
int n, m, cnt = 1, fix[5002], ans[5002];
int u, v;
vector<int> gr[5002];
void dfs(int p) {
  int i, t;
  fix[p] = 1;
  for (i = 0; i < gr[p].size(); i++) {
    t = gr[p][i];
    if (fix[t] == 0) dfs(t);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    memset(fix, 0, sizeof(fix));
    dfs(v);
    if (fix[u] > 0) {
      cnt = 2;
      ans[i] = 2;
    } else {
      ans[i] = 1;
      gr[u].push_back(v);
    }
  }
  cout << cnt << endl;
  for (int i = 0; i < m; i++) cout << ans[i] << ' ';
}
