#include <bits/stdc++.h>
using namespace std;
bool f = 0;
vector<int> v[5555];
bool vis[5555];
int a[5555];
void dfs(int x, int s) {
  vis[x] = 1;
  for (int i : v[x]) {
    if (i == s) {
      f = 1;
      return;
    }
    if (!vis[i]) dfs(i, s);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x < y)
      a[i] = 1;
    else
      a[i] = 2;
    v[x].push_back(y);
  }
  int k = 1;
  for (int i = 1; i <= n; i++) {
    f = 0;
    memset(vis, 0, sizeof(vis));
    dfs(i, i);
    if (f) {
      k = 2;
      break;
    }
  }
  printf("%d\n", k);
  if (k == 1) {
    for (int i = 0; i < m; i++) printf("1 ");
    printf("\n");
  } else {
    for (int i = 0; i < m; i++) printf("%d ", a[i]);
    printf("\n");
  }
}
