#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> taki;
vector<pair<int, int> > dota;
vector<pair<int, pair<int, int> > > ans;
vector<int> adj[N];
vector<int> cur;
bool mark[N];
void dfs(int a) {
  mark[a] = 1;
  cur.push_back(a);
  for (int p : adj[a])
    if (!mark[p]) dfs(p);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; i++)
    if (!mark[i]) {
      cur.clear();
      dfs(i);
      if (cur.size() > 3) {
        cout << -1;
        return 0;
      }
      if (cur.size() == 3) {
        ans.push_back({cur[0], {cur[1], cur[2]}});
      }
      if (cur.size() == 2) dota.push_back({cur[0], cur[1]});
      if (cur.size() == 1) taki.push_back(cur[0]);
    }
  if (taki.size() < dota.size()) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < dota.size(); i++) {
    ans.push_back({dota[i].first, {dota[i].second, taki[i]}});
  }
  for (int i = dota.size(); i < taki.size(); i += 3)
    ans.push_back({taki[i], {taki[i + 1], taki[i + 2]}});
  for (auto p : ans) {
    cout << p.first << " " << p.second.first << " " << p.second.second << endl;
  }
  return 0;
}
