#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, i, j, sz, was[50], a[50][4], len[50];
int main() {
  cin >> n >> m;
  for (i = 0; i < m; ++i) {
    cin >> x >> y;
    if (was[x] > 0 && was[y] > 0 && was[x] != was[y]) {
      cout << -1;
      return 0;
    }
    if (was[x] > 0 && was[y] == 0) {
      if (len[was[x]] == 3) {
        cout << -1;
        return 0;
      }
      was[y] = was[x];
      len[was[x]]++;
      a[was[x]][len[was[x]]] = y;
    }
    if (was[x] == 0 && was[y] > 0) {
      if (len[was[y]] == 3) {
        cout << -1;
        return 0;
      }
      was[x] = was[y];
      len[was[y]]++;
      a[was[y]][len[was[y]]] = x;
    }
    if (was[x] == 0 && was[y] == 0) {
      sz++;
      was[x] = sz;
      was[y] = sz;
      a[sz][1] = x;
      a[sz][2] = y;
      len[sz] = 2;
    }
  }
  for (i = 1; i <= n; ++i)
    if (!was[i]) {
      for (j = 1; j <= sz; ++j)
        if (len[j] < 3) {
          len[j]++;
          was[i] = j;
          a[j][len[j]] = i;
          break;
        }
      if (!was[i]) {
        sz++;
        len[sz] = 1;
        was[i] = sz;
        a[sz][1] = i;
      }
    }
  if (sz != n / 3)
    cout << -1;
  else
    for (i = 1; i <= sz; ++i)
      cout << a[i][1] << " " << a[i][2] << " " << a[i][3] << endl;
  return 0;
}
