import sys input = sys.stdin.readline sys.setrecursionlimit(1000000) class SCC: def __init__(self, n): self.n = n self.graph = [[] for i in range(n)] self.graph_rev = [[] for i in range(n)] self.used = [False]*n def add_edge(self, fr, to): if fr == to: return self.graph[fr].append(to) self.graph_rev[to].append(fr) def dfs(self, node, graph): self.used[node] = True for nex in graph[node]: if self.used[nex]: continue self.dfs(nex,graph) self.order.append(node) def first_dfs(self): self.used = [False]*self.n self.order = [] for i in range(self.n): if self.used[i]: continue self.dfs(i,self.graph) def second_dfs(self): self.used = [False]*self.n self.ans = [] for node in reversed(self.order): if self.used[node]: continue self.used[node] = True self.order = [] self.dfs(node, self.graph_rev) self.ans.append(self.order) def scc(self): self.first_dfs() self.second_dfs() return self.ans class Unionfind: def __init__(self,n): self.uf = [-1]*n def find(self,x): if self.uf[x] < 0: return x else: self.uf[x] = self.find(self.uf[x]) return self.uf[x] def same(self,x,y): return self.find(x) == self.find(y) def union(self,x,y): x = self.find(x) y = self.find(y) if x == y: return False if self.uf[x] > self.uf[y]: x,y = y,x self.uf[x] += self.uf[y] self.uf[y] = x return True def size(self,x): x = self.find(x) return -self.uf[x] n,m = map(int,input().split()) cand = set() uf = Unionfind(n) scc = SCC(n) deg = [0]*n for _ in range(m): u,v = map(int,input().split()) u,v = u-1,v-1 uf.union(u,v) scc.add_edge(u,v) cand.add(u) cand.add(v) deg[u] += 1 ok = 0 for i in cand: if deg[i]: continue ok = 1 if ok == 0: l = list(cand) ans = [] for i in range(len(l)): x = l[i] y = l[(i+1)%len(l)] ans.append((x,y)) print(len(ans)) for x,y in ans: print(x+1,y+1) exit() group = scc.scc() group.append([]) ans = [] for x,y in zip(group,group[1:]): if len(x) != 1: for i in range(len(x)): a = x[i] b = x[(i+1)%len(x)] ans.append((a,b)) if y == []: continue if uf.same(x[0],y[0]): ans.append((x[0],y[0])) print(len(ans)) for x,y in ans: print(x+1,y+1)