def find(v):
if p[v] != v:
p[v] = find(p[v])
return p[v]
def unite(u, v):
u = find(u)
v = find(v)
if u == v:
return False
p[u] = v
return True
n, m = map(int, input().split())
p = list(range(n))
edges = []
for _ in range(m):
u, v = map(int, input().split())
u -= 1
v -= 1
if not unite(u, v):
edges.append((u, v))
print(sum(p[i] == i for i in range(n)) - 1)
l1 = 0
l2 = 0
for u, v in edges:
while find(l1) != l1:
l1 += 1
l2 = max(l1 + 1, l2)
while l2 < n and find(l2) != l2:
l2 += 1
if l2 == n:
break
w = l2 if find(u) == l1 else l1
print(u + 1, v + 1, w + 1)
unite(u, w)