#include <bits/stdc++.h>
using namespace std;
vector<int> vv[55], g[55], pp;
int t = 1;
int arr[55], brr[55];
void dfs(int x) {
  arr[x] = t;
  for (int i = 0; i < vv[x].size(); i++) {
    int v = vv[x][i];
    if (!arr[v]) {
      dfs(v);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    vv[a].push_back(b);
    vv[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (!arr[i] && vv[i].size()) {
      dfs(i);
      t++;
    }
  }
  int p = 1;
  for (int i = 1; i <= n; i++) {
    if (!brr[i] && vv[i].size()) {
      for (int j = 1; j <= n; j++) {
        if (arr[i] == arr[j]) {
          g[p].push_back(j);
          brr[j] = 1;
        }
      }
      p++;
    }
  }
  for (int i = 1; i <= n / 3; i++) {
    if (g[i].size() > 3) {
      cout << "-1" << endl;
      return 0;
    }
    if (g[i].size() < 3) {
      for (int j = 1; j <= n && g[i].size() < 3; j++) {
        if (!brr[j]) {
          g[i].push_back(j);
          brr[j] = 1;
        }
      }
      if (g[i].size() < 3) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  for (int i = 1; i <= n / 3; i++) {
    for (int j = 0; j < g[i].size(); j++) cout << g[i][j] << " ";
    cout << endl;
  }
}
