#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
int n, m, a, b, vis[N], s[N];
vector<int> adj[N];
queue<int> q, ans;
int dfs(int u) {
  int ret = 0;
  vis[u] = 1;
  for (int v : adj[u]) {
    if (!vis[v]) {
      ret += dfs(v) + 1;
    }
  }
  return ret;
}
void DFS(int u) {
  vis[u] = 1;
  for (int v : adj[u]) {
    if (!vis[v]) {
      DFS(v);
    }
  }
  ans.push(u);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    memset(vis, 0, sizeof vis);
    s[i] = dfs(i);
    if (s[i] >= 3) {
      cout << -1 << endl;
      return 0;
    } else if (s[i] == 0) {
      q.push(i);
    }
  }
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= n; i++) {
    if (s[i] == 2 && !vis[i]) {
      DFS(i);
    } else if (s[i] == 1 && !vis[i]) {
      DFS(i);
      if (q.size()) {
        ans.push(q.front());
        q.pop();
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int c = 0;
  while (!q.empty()) {
    ans.push(q.front());
    q.pop();
    c++;
    if (c == 3) {
      c = 0;
    }
  }
  c = 0;
  while (!ans.empty()) {
    cout << ans.front() << " ";
    ans.pop();
    c++;
    if (c == 3) {
      c = 0;
      cout << endl;
    }
  }
  return 0;
}
