#include <bits/stdc++.h>
using namespace std;
struct edge {
  int nex, to;
} e[10005];
int pin, hr[10005], a[10005], b[10005], n, m;
bool inq[10005], u[10005];
inline int read() {
  int n = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    n = n * 10 + c - '0';
    c = getchar();
  }
  return n * f;
}
inline void ins(int x, int y) {
  e[++pin] = (edge){hr[x], y};
  hr[x] = pin;
}
bool dfs(int x) {
  if (inq[x]) return true;
  if (u[x]) return false;
  inq[x] = u[x] = true;
  for (int i = hr[x]; i; i = e[i].nex)
    if (dfs(e[i].to)) return true;
  inq[x] = false;
  return false;
}
int main() {
  register int i, j, k, lj, lt, tl;
  n = read();
  m = read();
  for (i = 1; i <= m; ++i) a[i] = read(), b[i] = read(), ins(a[i], b[i]);
  for (i = 1; i <= n; ++i)
    if (!u[i]) {
      if (dfs(i)) break;
    }
  if (i <= n) {
    puts("2");
    for (i = 1; i <= m; ++i)
      if (a[i] < b[i])
        printf("1 ");
      else
        printf("2 ");
  } else {
    puts("1");
    for (i = 1; i <= m; ++i) printf("1 ");
  }
}
