import sys sys.setrecursionlimit(10**7) def main(): N,M = map(int,input().split()) Q = [] S = set([]) for i in range(M): U,V = map(int,input().split()) Q.append((U,V)) S.add(U) S.add(V) L = list(S) n = len(S) #出てくる頂点の種類 L.sort() dic = {} #元の番号→座圧後の番号 revdic = {} #座圧後の番号→元の番号 for i in range(n): dic[L[i]] = i revdic[i] = L[i] ALL = [i for i in range(n)] ALL = set(ALL) G = [[] for _ in range(n)] for u,v in Q: uz = dic[u] vz = dic[v] G[uz].append(vz) ALL.discard(vz) used = set([]) TS = [] def dfs(v): if v in used: return used.add(v) for w in G[v]: if w in used: continue dfs(w) TS.append(w) #帰りがけで記録 for root in ALL: #すべての始点について dfs(root) TS.append(root) TS.reverse() #最後に反転 #print(TS) print(n-1) #何本か? for i in range(n-1): s = TS[i] t = TS[i+1] sori = revdic[s] tori = revdic[t] ret = [sori, tori] print(*ret) if __name__ == '__main__': main()