#include <bits/stdc++.h>
using namespace std;
const int MAX = 1 << 17;
int p[MAX];
int find(int v)
{
return p[v] == v ? v : p[v] = find(p[v]);
}
bool unite(int u, int v)
{
u = find(u);
v = find(v);
if(u == v)
return false;
p[u] = v;
return true;
}
int main()
{
int n, m;
cin >> n >> m;
iota(p, p + n, 0);
vector<pair<int, int> > edges;
while(m--)
{
int u, v;
cin >> u >> v;
u--;
v--;
if(!unite(u, v))
edges.push_back({u, v});
}
set<int> leaders;
for(int i = 0; i < n; i++)
leaders.insert(find(i));
cout << leaders.size() - 1 << "\n";
for(auto uv: edges)
{
int u = uv.first, v = uv.second;
if(leaders.size() == 1)
break;
auto it = leaders.begin();
if(*it == find(u))
it++;
int w = *it;
cout << u + 1 << " " << v + 1 << " " << w + 1 << "\n";
leaders.erase(it);
leaders.erase(find(u));
unite(u, w);
leaders.insert(find(u));
}
assert(leaders.size() == 1);
return 0;
}