#include <bits/stdc++.h>
using namespace std;
const int N = 60;
bool visit[N];
vector<int> adj[N], team, noteam;
vector<vector<int> > teams;
void dfs(int u) {
  if (visit[u]) return;
  visit[u] = 1, team.push_back(u);
  for (int i = 0; i < (int)adj[u].size(); i++) dfs(adj[u][i]);
}
void read(int &n) {
  int m;
  cin >> n >> m;
  while (m--) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v), adj[v].push_back(u);
  }
}
int main() {
  int n;
  read(n);
  for (int i = 1; i <= n; i++)
    if (adj[i].size() == 0)
      noteam.push_back(i);
    else if (!visit[i]) {
      team.clear();
      dfs(i);
      if (team.size() > 3) return cout << "-1\n", 0;
      teams.push_back(team);
    }
  for (int i = 0; i < (int)teams.size(); i++) {
    while (teams[i].size() != 3 && noteam.size())
      teams[i].push_back(noteam.back()), noteam.pop_back();
    if (teams[i].size() != 3) return cout << "-1\n", 0;
  }
  for (int i = 0; i < (int)teams.size(); i++) {
    for (int j = 0; j < (int)teams[i].size(); j++) cout << teams[i][j] << ' ';
    cout << "\n";
  }
  for (int i = 0; i < (int)noteam.size(); i++) {
    if (i && i % 3 == 0) cout << '\n';
    cout << noteam[i] << ' ';
  }
  return 0;
}
