#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  fast();
  int n, m, i, k = 1, j, a, b;
  cin >> n >> m;
  vector<bool> vs(n + 1, false);
  vector<bool> vst(n + 1, false);
  vector<int> f(n + 1);
  vector<vector<int> > v;
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    vst[a] = vst[b] = true;
    if (vs[a] == true && vs[b] == true) {
      if (f[a] != f[b]) {
        cout << -1;
        return 0;
      }
    } else if (vs[a] == true) {
      v[f[a]].push_back(b);
      if (v[f[a]].size() > 3) {
        cout << -1;
        return 0;
      }
      f[b] = f[a];
      vs[b] = true;
    } else if (vs[b] == true) {
      v[f[b]].push_back(a);
      if (v[f[b]].size() > 3) {
        cout << -1;
        return 0;
      }
      f[a] = f[b];
      vs[a] = true;
    } else {
      f[a] = f[b] = v.size();
      vector<int> p;
      p.push_back(a);
      p.push_back(b);
      v.push_back(p);
      vs[a] = vs[b] = true;
    }
  }
  int fl = 0, co = 0;
  for (k = 1; k <= n; k++) {
    if (vst[k] == false) co++;
  }
  for (i = 0; i < v.size(); i++) {
    if (v[i].size() < 3) fl++;
  }
  if (co < fl) {
    cout << "-1";
    return 0;
  }
  k = 1;
  for (i = 0; i < v.size(); i++) {
    for (j = 0; j < v[i].size(); j++) {
      cout << v[i][j] << " ";
    }
    for (j = v[i].size(); j < 3; j++) {
      for (; k <= n; k++) {
        if (vst[k] == false) {
          vst[k] = true;
          cout << k << " ";
          break;
        }
      }
    }
    cout << "\n";
  }
  int c = 0;
  for (; k <= n; k++) {
    if (c == 3) {
      cout << "\n";
      c = 0;
      k--;
      continue;
    }
    if (vst[k] == false) {
      vst[k] = true;
      cout << k << " ";
      c++;
    }
  }
  return 0;
}
