#include <bits/stdc++.h>
using namespace std;
int adj[50][50];
int assigned[50] = {0};
int m, n;
void rec(int i, vector<int> &v) {
  if (assigned[i]) {
    return;
  }
  assigned[i] = 1;
  v.push_back(i);
  for (int j = 1; j <= n; j++) {
    if (adj[i][j]) {
      rec(j, v);
    }
  }
}
int main() {
  cin >> n >> m;
  vector<vector<int>> backets;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a][b] = 1;
    adj[b][a] = 1;
  }
  for (int i = 1; i <= n; i++) {
    vector<int> v;
    if (!assigned[i]) {
      rec(i, v);
    }
    if (v.size() > 0) {
      backets.push_back(v);
    }
  }
  vector<vector<int>> res;
  int hh[50] = {0};
  for (int i = 0; i < backets.size(); i++) {
    if (backets[i].size() == 2) {
      for (int j = 0; j < backets.size(); j++) {
        if (backets[j].size() == 1 && !hh[backets[j][0]]) {
          vector<int> v;
          v.push_back(backets[j][0]);
          v.insert(v.end(), backets[i].begin(), backets[i].end());
          res.push_back(v);
          hh[backets[j][0]] = 1;
          break;
        }
      }
    } else if (backets[i].size() == 3) {
      res.push_back(backets[i]);
    }
  }
  int c = 0;
  vector<int> temp;
  for (int i = 0; i < backets.size(); i++) {
    if (backets[i].size() == 1 && !hh[backets[i][0]]) {
      temp.push_back(backets[i][0]);
      c++;
    }
    if (c > 0 && c % 3 == 0) {
      vector<int> v;
      v.insert(v.end(), temp.begin(), temp.end());
      res.push_back(v);
      temp.clear();
    }
  }
  if (res.size() != n / 3) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < res.size(); i++) {
    for (int j = 0; j < 3; j++) {
      cout << res[i][j] << ' ';
    }
    cout << endl;
  }
}
