#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, j;
  cin >> n >> m;
  int a[n + 1], i, aa, bb, t = 1, f = 0;
  memset(a, 0, sizeof(a));
  for (i = 0; i < m; i++) {
    cin >> aa >> bb;
    if (a[aa] != 0 && a[bb] != 0 && a[aa] != a[bb])
      f = 1;
    else if (a[aa] != 0 && a[bb] == 0)
      a[bb] = a[aa];
    else if (a[aa] == 0 && a[bb] != 0)
      a[aa] = a[bb];
    else if (a[aa] == 0 && a[bb] == 0) {
      a[aa] = t;
      a[bb] = t;
      t++;
    }
  }
  if (f == -1)
    cout << "-1\n";
  else {
    int cnt[t + 1];
    memset(cnt, 0, sizeof(cnt));
    vector<int> team[n / 3 + 3];
    for (i = 1; i <= n; i++) {
      cnt[a[i]]++;
      team[a[i]].push_back(i);
      if (cnt[a[i]] > 3 && a[i] != 0) f = 1;
    }
    if (f == 1)
      cout << "-1\n";
    else {
      for (i = 1; i <= t - 1; i++) {
        if (team[i].size() != 0 && team[i].size() != 3) {
          if (team[i].size() == 1 && team[0].size() >= 2) {
            int a = team[0][team[0].size() - 1];
            int b = team[0][team[0].size() - 2];
            team[0].pop_back();
            team[0].pop_back();
            team[i].push_back(a);
            team[i].push_back(b);
          } else if (team[i].size() == 2 && team[0].size() >= 1) {
            int a = team[0][team[0].size() - 1];
            team[0].pop_back();
            team[i].push_back(a);
          } else {
            f = 1;
            break;
          }
        }
      }
      if (team[0].size() % 3 == 0) {
        while (team[0].size() > 3) {
          int a = team[0][team[0].size() - 1];
          int b = team[0][team[0].size() - 2];
          int c = team[0][team[0].size() - 3];
          team[t].push_back(a);
          team[t].push_back(b);
          team[t].push_back(c);
          team[0].pop_back();
          team[0].pop_back();
          team[0].pop_back();
          t++;
        }
      }
      if (f == 1 || (team[0].size() != 0 && team[0].size() != 3)) {
        cout << "-1\n";
        return 0;
      }
      for (i = 0; i <= t - 1; i++) {
        for (j = 0; j < team[i].size(); j++) cout << team[i][j] << " ";
        if (team[i].size() == 3) cout << endl;
      }
    }
  }
  return 0;
}
