You are given a directed graph with n vertices and m directed edges without self-loops or multiple edges.

Let's denote the k-coloring of a digraph as following: you color each edge in one of k colors. The k-coloring is good if and only if there no cycle formed by edges of same color.

Find a good k-coloring of given digraph with minimum possible k.

Input

The first line contains two integers n and m (2 ≤ n ≤ 5000, 1 ≤ m ≤ 5000) — the number of vertices and edges in the digraph, respectively.

Next m lines contain description of edges — one per line. Each edge is a pair of integers u and v (1 ≤ u, v ≤ n, u ≠ v) — there is directed edge from u to v in the graph.

It is guaranteed that each ordered pair (u, v) appears in the list of edges at most once.

Output

In the first line print single integer k — the number of used colors in a good k-coloring of given graph.

In the second line print m integers c_1, c_2, ..., c_m (1 ≤ c_i ≤ k), where c_i is a color of the i-th edge (in order as they are given in the input).

If there are multiple answers print any of them (you still have to minimize k).

Examples

Input


4 5
1 2
1 3
3 4
2 4
1 4


Output


1
1 1 1 1 1 


Input


3 3
1 2
2 3
3 1


Output


2
1 1 2 
#include <bits/stdc++.h>
using namespace std;
struct Dummyf {
  template <typename... Ts>
  void operator()(Ts&&...) {}
};
struct Graph {
  struct Edge {
    int dst, id;
    operator int() const { return dst; }
  };
  Graph(int n) : edges(n) {}
  void addEdge1(int a, int b, int id) { edges[a].push_back({b, id}); }
  void addEdge2(int a, int b, int id) {
    addEdge1(a, b, id);
    addEdge1(b, a, id);
  }
  int size() const { return (int)edges.size(); }
  vector<vector<Edge>> edges;
  template <typename Pre = Dummyf, typename Post = Dummyf,
            typename PreE = Dummyf, typename PostE = Dummyf,
            typename FailE = Dummyf>
  void implDFS(int v, vector<bool>& visit, Pre pre, Post post, PreE pree,
               PostE poste, FailE faile) const {
    visit[v] = true;
    pre(v);
    for (auto u : edges[v])
      if (not visit[u])
        pree(v, u), implDFS(u, visit, pre, post, pree, poste, faile),
            poste(v, u);
      else
        faile(v, u);
    post(v);
  }
  template <typename Pre = Dummyf, typename Post = Dummyf,
            typename PreE = Dummyf, typename PostE = Dummyf,
            typename FailE = Dummyf>
  void allDFS(Pre pre, Post post, PreE pree, PostE poste, FailE faile) const {
    auto visit = vector<bool>(size(), false);
    for (auto v = 0; v < size(); ++v)
      if (not visit[v]) implDFS(v, visit, pre, post, pree, poste, faile);
  }
  template <typename F1>
  void tarjan(F1 f1) const {
    auto enter = vector<int>(size(), -1);
    auto low = vector<int>(size(), -1);
    auto t = 0;
    auto stack = vector<int>();
    auto active = vector<bool>(size(), false);
    allDFS(
        [&](int v) {
          enter[v] = low[v] = t++;
          stack.push_back(v);
          active[v] = true;
        },
        [&](int v) {
          if (enter[v] == low[v]) {
            auto f2 = f1(v);
            while (active[v]) {
              auto u = stack.back();
              stack.pop_back();
              active[u] = false;
              f2(u);
            }
          }
        },
        {}, [&](int v, int u) { low[v] = min(low[v], low[u]); },
        [&](int v, int u) {
          if (active[u]) low[v] = min(low[v], enter[u]);
        });
  }
};
template <typename T>
T load() {
  T r;
  cin >> r;
  return r;
}
template <typename T>
vector<T> loadMany(int n) {
  vector<T> rs(n);
  generate(rs.begin(), rs.end(), &load<T>);
  return rs;
}
Graph loadEdges(int n, int m) {
  auto g = Graph(n);
  for (auto i = 0; i < m; ++i) {
    auto v = load<int>() - 1;
    auto u = load<int>() - 1;
    g.addEdge1(v, u, i);
  }
  return g;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  auto n = load<int>();
  auto m = load<int>();
  auto graph = loadEdges(n, m);
  auto scc_count = 0;
  auto ord = vector<int>();
  graph.tarjan([&](int) {
    ++scc_count;
    return [&](int v) { ord.push_back(v); };
  });
  if (scc_count == n) {
    cout << "1\n";
    for (auto i = 0; i < m; ++i) cout << "1 ";
    cout << '\n';
  } else {
    cout << "2\n";
    auto visit = vector<bool>(n, false);
    auto col = vector<int>(m, 1);
    auto height = vector<int>(n, 0);
    for (auto v : ord)
      if (not visit[v])
        graph.implDFS(
            v, visit, {}, {},
            [&](int v, Graph::Edge u) {
              col[u.id] = 2;
              height[u] = height[v] + 1;
            },
            {},
            [&](int v, Graph::Edge u) {
              if (height[u] > height[v]) col[u.id] = 2;
            });
    for (auto c : col) cout << c << ' ';
    cout << '\n';
  }
}
