#include <bits/stdc++.h>   using namespace std;   template <class T>   istream &operator>>(istream &in, vector<T> &arr) {     for (auto &x : arr) in >> x;     return in;   }   long long n, m;   const long long N = 1e6 + 100;   vector<pair<long long, long long>> g[N];   long long col[N];   bool cyc;   long long res[N];   void dfs(long long r) {     col[r] = 1;     for (auto x : g[r]) {       long long to = x.first, ind = x.second;       if (col[to] == 0) {         res[ind] = 1;         dfs(to);       } else if (col[to] == 1) {         res[ind] = 2;         cyc = true;       } else {         res[ind] = 1;       }     }     col[r] = 2;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (long long i = 0; i < m; ++i) {       long long u, v;       cin >> u >> v;       --u, --v;       g[u].push_back({v, i});     }     for (long long i = 0; i < n; ++i) {       if (col[i] == 0) {         dfs(i);       }     }     cout << (cyc ? 2 : 1) <<   n ;     for (long long i = 0; i < m; ++i) {       cout << res[i] <<    ;     }   }   