#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, a, b;
  cin >> n >> m;
  vector<vector<int> > adj(n);
  for (int i = 0; i < (int)m; i++) {
    cin >> a >> b;
    a--, b--;
    adj[a].emplace_back(b);
    adj[b].emplace_back(a);
  }
  vector<int> vis(n, 0);
  int c = 0;
  vector<int> ans;
  function<void(int)> dfs = [&](int i) {
    vis[i] = 1;
    ans.push_back(i + 1);
    c++;
    for (int v : adj[i]) {
      if (!vis[v]) {
        dfs(v);
      }
    }
  };
  vector<int> p[3];
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      ans.clear();
      c = 0;
      dfs(i);
      if (c > 3) {
        cout << -1 << "\n";
        return 0;
      }
      for (int first = 0; first < (int)c; first++)
        p[c - 1].push_back(ans[first]);
    }
  }
  if (2 * (int)(p[0].size()) < (int)(p[1].size())) {
    cout << -1 << "\n";
    return 0;
  }
  for (int i = 0; i < (int)(p[2].size()); i += 3)
    cout << p[2][i] << " " << p[2][i + 1] << " " << p[2][i + 2] << "\n";
  int i = 0;
  for (int i2 = 0; i2 < (int)(p[1].size()); i2 += 2) {
    cout << p[0][i] << " " << p[1][i2] << " " << p[1][i2 + 1] << "\n";
    i++;
  }
  for (; i < (int)(p[0].size()); i += 3) {
    cout << p[0][i] << " " << p[0][i + 1] << " " << p[0][i + 2] << "\n";
  }
}
