#include <bits/stdc++.h>
using namespace std;
const int N = 10000;
int res[N], fix[N];
bool cycle;
vector<pair<int, int> > edges[N];
void dfs(int x, bool p) {
  fix[x] = 1;
  for (int i = 0; i < edges[x].size(); i++) {
    int u = edges[x][i].first;
    if (fix[u] == 1)
      cycle = true, res[edges[x][i].second] = (p ^ 1) + 1;
    else
      res[edges[x][i].second] = p + 1;
    if (!fix[u]) dfs(u, p);
  }
  fix[x] = 2;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    edges[a].push_back({b, i});
  }
  for (int i = 1; i <= n; i++)
    if (!fix[i]) dfs(i, 0);
  cout << (cycle ? 2 : 1) << "\n";
  for (int i = 1; i <= m; i++) cout << res[i] << " \n"[i == m];
}
