#include <bits/stdc++.h>
using namespace std;
const int maxn = 125002;
int n, k, cur[maxn], sas[maxn], w[maxn];
vector<pair<int, int> > g[maxn], e;
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    e.push_back({x, y});
    if (x > y) swap(x, y);
    g[y].push_back({x, i});
    cur[x]++;
    cur[y]++;
    w[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    set<int> second;
    for (auto it : g[i]) {
      second.insert(cur[it.first]);
      if (!sas[it.first]) {
        sas[it.first]++;
        w[it.second]--;
        cur[i]--;
      }
    }
    for (auto it : g[i]) {
      if (!second.count(cur[i])) break;
      sas[it.first]--;
      w[it.second]++;
      cur[i]++;
    }
  }
  vector<int> res;
  for (int i = 1; i <= n; i++)
    if (sas[i]) res.push_back(i);
  cout << res.size() << endl;
  for (auto it : res) cout << it << ' ';
  puts("");
  for (int i = 0; i < k; i++)
    cout << e[i].first << ' ' << e[i].second << ' ' << w[i] << '\n';
  return 0;
}
