#include <bits/stdc++.h>
using namespace std;
bool prime[100005] = {false};
void sieve() {
  prime[0] = true;
  prime[1] = true;
  for (long long i = 2; i < 100005; i++) {
    if (prime[i] == false) {
      for (long long j = i * i; j < 100005; j += i) prime[j] = true;
    }
  }
}
long long n, m, a, b, x, answer = 1, cnt = 0, v;
bool vis[50] = {false}, vis2[50] = {false};
vector<long long> ad[50];
vector<pair<long long, long long> > edges;
vector<long long> ans[50];
void bfs(long long x) {
  vis2[x] = true;
  queue<long long> q;
  q.push(x);
  ans[answer].push_back(x);
  while (!q.empty()) {
    v = q.front();
    q.pop();
    for (auto u : ad[v]) {
      if (!vis2[u]) {
        vis2[u] = true;
        q.push(u);
        ans[answer].push_back(u);
      }
    }
  }
}
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> a >> b;
    ad[a].push_back(b);
    ad[b].push_back(a);
    vis[a] = true;
    vis[b] = true;
  }
  long long j = 1;
  for (long long i = 1; i <= n; i++) {
    if (vis[i] && !vis2[i]) {
      bfs(i);
      if (ans[answer].size() > 3) {
        cout << -1;
        return;
      }
      while (ans[answer].size() < 3) {
        while (vis[j] && j <= n) j++;
        if (j > n) {
          cout << -1;
          return;
        }
        ans[answer].push_back(j);
        j++;
      }
      answer++;
    }
  }
  while (j <= n) {
    if (vis[j]) {
      j++;
      continue;
    }
    cnt++;
    ans[answer].push_back(j);
    if (cnt == 3) {
      cnt = 0;
      answer++;
    }
    j++;
  }
  for (long long i = 1; i <= answer - 1; i++) {
    cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2];
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
