#include <bits/stdc++.h>
using namespace std;
const int MAXn = 48 + 10;
vector<int> g[MAXn], vec, teams[MAXn], ones;
vector<pair<int, int> > twos;
int n, m, cnt;
bool flag[MAXn];
void dfs(int a) {
  flag[a] = true;
  vec.push_back(a);
  for (int i = 0; i < g[a].size(); i++)
    if (!flag[g[a][i]]) dfs(g[a][i]);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 0; i < n; i++)
    if (!flag[i]) {
      vec.clear();
      dfs(i);
      if (vec.size() > 3) {
        return cout << -1, 0;
      }
      if (vec.size() == 3) {
        for (int j = 0; j < 3; j++) teams[cnt].push_back(vec[j]);
        cnt++;
      } else if (vec.size() == 2) {
        twos.push_back(pair<int, int>(vec[0], vec.back()));
      } else {
        ones.push_back(vec.back());
      }
    }
  if (ones.size() < twos.size()) return cout << -1, 0;
  if (((int)ones.size() - twos.size()) % 3) return cout << -1, 0;
  for (int i = 0; i < cnt; i++)
    cout << teams[i][0] + 1 << ' ' << teams[i][1] + 1 << ' ' << teams[i][2] + 1
         << endl;
  for (int i = 0; i < twos.size(); i++)
    cout << ones[i] + 1 << ' ' << twos[i].first + 1 << ' ' << twos[i].second + 1
         << endl;
  for (int i = twos.size(); i < ones.size(); i += 3)
    cout << ones[i] + 1 << ' ' << ones[i + 1] + 1 << ' ' << ones[i + 2] + 1
         << endl;
}
