def choice(s): for i in s: return i def remove_edge(f, t, succ, pred, zero): succ[f][t] = succ[f][t] - 1 if succ[f][t] == 0: del succ[f][t] pred[t][f] = pred[t][f] - 1 if pred[t][f] == 0: del pred[t][f] if len(succ[f]) == 0: zero.append(f) N, M = map(int, input().split()) succ = [{} for i in range(N)] pred = [{} 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][t - 1] = succ[f - 1].get(t - 1, 0) + 1 pred[t - 1][f - 1] = pred[t - 1].get(f - 1, 0) + 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] erase = [] for f in pred[t]: erase += [(f, t)] * succ[f][t] for e in erase: ans.append(e) remove_edge(e[0], e[1], 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)