#include <bits/stdc++.h>
using namespace std;
vector<int> g[50];
int done[50];
unordered_set<int> team;
vector<tuple<int, int, int>> ans;
void rec(int orang) {
  team.insert(orang);
  done[orang] = 1;
  for (auto &e : g[orang]) {
    if (!done[e]) {
      rec(e);
    }
  }
}
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  unordered_set<int> z;
  for (int i = 0; i <= n - 1; i++) {
    z.insert(i + 1);
  }
  for (int i = 0; i <= m - 1; i++) {
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    g[a].push_back(b);
    g[b].emplace_back(a);
    z.erase(a);
    z.erase(b);
  }
  for (int i = 1; i <= n; i++) {
    vector<int> temp;
    if (done[i]) {
      continue;
    }
    if ((int)g[i].size() != 0) {
      rec(i);
    }
    if ((int)team.size() > 3) {
      puts("-1");
      return 0;
    }
    if ((int)team.size() == 0) {
      continue;
    }
    if ((int)team.size() == 2 && z.empty()) {
      puts("-1");
      return 0;
    }
    if ((int)team.size() == 2) {
      if ((int)z.size() > 0) {
        for (auto &e : team) {
          temp.emplace_back(e);
        }
        ans.emplace_back(temp[0], temp[1], *z.begin());
        z.erase(*z.begin());
      }
    } else {
      for (auto &e : team) {
        temp.emplace_back(e);
      }
      ans.emplace_back(temp[0], temp[1], temp[2]);
    }
    team.clear();
  }
  for (auto &e : ans) {
    printf("%d %d %d\n", get<0>(e), get<1>(e), get<2>(e));
  }
  while (!z.empty()) {
    for (int i = 0; i <= 2; i++) {
      if ((int)z.size() > 0) {
        printf("%d ", *z.begin());
        z.erase(*z.begin());
      }
    }
    puts("");
    if (z.empty()) {
      break;
    }
  }
  return 0;
}
