#include <bits/stdc++.h>
using namespace std;
const int N = 5007, mod = 998244353;
int n, m;
pair<int, int> a[N];
vector<int> v[N];
bool f[N];
int d[N];
int main() {
  cin >> n >> m;
  int flag = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].first, &a[i].second);
    v[a[i].first].push_back(a[i].second);
    d[a[i].second]++;
  }
  for (int i = 1; i <= n; i++) {
    int mn = 0;
    for (int j = 1; j <= n; j++) {
      if (d[j] == 0 && f[j] == 0) mn = j;
    }
    f[mn] = 1;
    if (mn == 0) {
      flag = 1;
      break;
    }
    for (int j = 0; j < v[mn].size(); j++) {
      d[v[mn][j]]--;
    }
  }
  if (flag == 0) {
    cout << 1 << '\n';
    for (int i = 1; i <= m; i++) {
      printf("1 ");
    }
  } else {
    cout << 2 << '\n';
    for (int i = 1; i <= m; i++) {
      if (a[i].first < a[i].second)
        printf("1 ");
      else
        printf("2 ");
    }
  }
  return 0;
}
