#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool checkMin(T& a, T b) {
  return (a > b ? a = b, 1 : 0);
}
template <class T>
inline bool checkMax(T& a, T b) {
  return (a < b ? a = b, 1 : 0);
}
const int N = 5005;
vector<int> e[N];
int n, m;
void init() { scanf("%d%d", &n, &m); }
int vis[N];
void dfs(int u) {
  if (vis[u]) return;
  vis[u] = 1;
  for (int i = 0; i < (int)e[u].size(); i++) {
    int vv = e[u][i];
    dfs(vv);
  }
}
int ss[N];
void solve() {
  int ans = 1;
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    memset(vis, 0, sizeof(vis));
    dfs(v);
    if (vis[u]) {
      ans = 2;
      ss[i] = ans;
    } else {
      e[u].push_back(v);
      ss[i] = 1;
    }
  }
  printf("%d\n", ans);
  for (int i = 0; i < m; i++) printf("%d ", ss[i]);
}
int main() {
  init();
  solve();
  return 0;
}
