#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = 1000000007) {
  return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = 1000000007) {
  return (a % p + b % p) % p;
}
long long fpow(long long n, long long k, long long p = 1000000007) {
  long long r = 1;
  for (; k; k >>= 1LL) {
    if (k & 1LL) r = mult(r, n, p);
    n = mult(n, n, p);
  }
  return r;
}
long long inv(long long a, long long p = 1000000007) {
  return fpow(a, p - 2, p);
}
vector<int> v[100001];
vector<pair<int, int> > edges;
int col[100001];
bool cyc;
bool al[100001];
bool curr[100001];
bool cycle(int s) {
  curr[s] = true;
  for (int i : v[s]) {
    if (curr[i]) {
      return true;
    } else if (!al[i] && cycle(i)) {
      return true;
    }
  }
  curr[s] = false;
  al[s] = true;
  return false;
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    edges.push_back(make_pair(a, b));
  }
  for (int i = 1; i < n + 1; i++) {
    if (!al[i] && cycle(i)) {
      cyc = true;
      break;
    }
  }
  if (cyc) {
    cout << 2 << '\n';
    for (int i = 0; i < m; i++) {
      if (edges[i].first > edges[i].second)
        cout << 1 << " ";
      else
        cout << 2 << " ";
    }
    cout << '\n';
  } else {
    cout << 1 << '\n';
    for (int i = 0; i < m; i++) cout << 1 << " ";
    cout << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
