#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50;
vector<int> adj[MAXN];
int vis[MAXN];
int cnt = 0;
vector<int> path;
typedef struct group {
  int a, b, c;
  group(){};
  group(int a, int b, int c) : a(a), b(b), c(c) {}
} group;
vector<group> groups;
void dfs(int u) {
  vis[u] = 1;
  path.push_back(u);
  cnt++;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (!vis[v]) {
      dfs(v);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  memset(vis, 0, sizeof(vis));
  bool ok = true;
  vector<group> g1, g2, g3;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      cnt = 0;
      path.clear();
      dfs(i);
      if (cnt > 3) {
        ok = false;
        break;
      } else if (cnt == 3) {
        g3.push_back(group(path[0], path[1], path[2]));
      } else if (cnt == 2) {
        g2.push_back(group(path[0], path[1], -1));
      } else if (cnt == 1) {
        g1.push_back(group(path[0], -1, -1));
      }
    }
  }
  if ((g2.size() > g1.size()) || ((g1.size() - g2.size()) % 3 != 0)) {
    ok = false;
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  } else {
    for (int i = 0; i < g3.size(); i++) {
      cout << g3[i].a + 1 << " " << g3[i].b + 1 << " " << g3[i].c + 1 << endl;
    }
    for (int i = 0; i < g2.size(); i++) {
      int a = g1.back().a;
      g1.pop_back();
      cout << g2[i].a + 1 << " " << g2[i].b + 1 << " " << a + 1 << endl;
    }
    for (int i = 0; i < g1.size() / 3; i++) {
      cout << g1[3 * i].a + 1 << " " << g1[3 * i + 1].a + 1 << " "
           << g1[3 * i + 2].a + 1 << endl;
    }
  }
}
