def choice(s): ret = s.pop() s.add(ret) return ret def remove_edge(f, t, succ, pred, zero): succ[f].discard(t) pred[t].discard(f) if len(succ[f]) == 0: zero.append(f) N, M = map(int, input().split()) succ = [set() for i in range(N)] pred = [set() for i in range(N)] zero = [] zero_p = 0 start = 0 ans = [] for i in range(M): f, t = map(int, input().split()) succ[f - 1].add(t - 1) pred[t - 1].add(f - 1) for i in range(N): if len(succ[i]) == 0: zero.append(i) while 1: while len(zero) > zero_p: t = zero[zero_p] while len(pred[t]) > 0: f = pred[t].pop() ans.append((f, t)) remove_edge(f, t, succ, pred, zero) zero_p += 1 if zero_p == N: break while len(succ[start]) == 0: start = (start + 1) % N path = [start] path_s = set(path) while 1: nex = choice(succ[path[-1]]) path.append(nex) if nex in path_s: break path_s.add(nex) for i in range(path.index(nex), len(path) - 1): remove_edge(path[i], path[i + 1], succ, pred, zero) print(N, len(ans)) for i in ans: print(i[0] + 1, i[1] + 1)