#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
double rast(int x1, int y1, int x2, int y2) {
  return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
vector<int> g[10000];
bool has_cycle = false;
int used[10005];
void dfs(int v) {
  used[v] = 1;
  for (int to : g[v]) {
    if (used[to] == 1)
      has_cycle = true;
    else if (used[to] == 0)
      dfs(to);
  }
  used[v] = 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > edges;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    edges.push_back({l, r});
    g[l].push_back(r);
  }
  for (int i = 0; i < n; i++)
    if (!used[i]) dfs(i);
  if (!has_cycle) {
    cout << 1 << '\n';
    for (int i = 0; i < m; i++) cout << 1 << " ";
  } else {
    cout << 2 << '\n';
    for (int i = 0; i < m; i++)
      if (edges[i].first < edges[i].second)
        cout << 1 << " ";
      else
        cout << 2 << " ";
  }
}
