#include <bits/stdc++.h>
using namespace std;
bool vis[50];
bool OK(vector<set<int> > v) {
  for (int i = 0; i < (int)v.size(); i++)
    if ((int)v[i].size() > 3) return 1;
  return 0;
}
int Find(vector<set<int> > v, int x) {
  for (int i = 0; i < (int)v.size(); i++)
    if (find(v[i].begin(), v[i].end(), x) != v[i].end()) return i;
  return -1;
}
int main() {
  int n, q, x, y, ex, ey, c = 0;
  scanf("%d %d", &n, &q);
  if (n % 3) {
    cout << -1;
    return 0;
  }
  vector<set<int> > v(n / 3);
  while (q--) {
    scanf("%d %d", &x, &y);
    vis[x] = 1, vis[y] = 1;
    ex = Find(v, x), ey = Find(v, y);
    if (ex != -1)
      v[ex].insert(y);
    else if (ey != -1)
      v[ey].insert(x);
    else {
      if (c == n / 3) {
        cout << -1;
        return 0;
      }
      v[c].insert(x), v[c].insert(y), c++;
    }
  }
  if (OK(v)) {
    cout << -1;
    return 0;
  }
  c = 1;
  for (int i = 0; i < (int)v.size(); i++) {
    for (int j = 0; j < 3 - (int)v[i].size(); j++) {
      for (int k = c; k < n + 1; k++)
        if (!vis[k]) {
          v[i].insert(k);
          c = k + 1;
          j--;
          break;
        }
    }
  }
  for (int i = 0; i < (int)v.size(); i++) {
    for (set<int>::iterator it = v[i].begin(); it != v[i].end(); it++)
      printf("%d ", *it);
    printf("\n");
  }
}
