#include <bits/stdc++.h>
using namespace std;
vector<bool> used;
vector<list<int> > G;
vector<int> ans1;
vector<int> ans2;
vector<int> ans3;
vector<int> ans_one;
vector<int> ans_two1;
vector<int> ans_two2;
vector<int> tmp;
void DFS(int u) {
  used[u] = true;
  tmp.push_back(u);
  for (list<int>::iterator it = G[u].begin(); it != G[u].end(); it++) {
    if (!used[*it]) DFS(*it);
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  used = vector<bool>(N);
  G = vector<list<int> >(N);
  for (long long i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  bool flag = true;
  for (long long i = 0; i < N; i++) {
    tmp.clear();
    if (!used[i]) {
      DFS(i);
      if (tmp.size() == 3) {
        ans1.push_back(tmp[0]);
        ans2.push_back(tmp[1]);
        ans3.push_back(tmp[2]);
      } else if (tmp.size() == 1) {
        ans_one.push_back(tmp[0]);
      } else if (tmp.size() == 2) {
        ans_two1.push_back(tmp[0]);
        ans_two2.push_back(tmp[1]);
      } else
        flag = false;
    }
  }
  if (flag && ans_two1.size() <= ans_one.size()) {
    for (long long i = 0; i < ans1.size(); i++)
      cout << ans1[i] + 1 << " " << ans2[i] + 1 << " " << ans3[i] + 1 << endl;
    int i = 0;
    for (; i < ans_two1.size(); i++) {
      cout << ans_two1[i] + 1 << " " << ans_two2[i] + 1 << " " << ans_one[i] + 1
           << endl;
    }
    for (int j = i; j < ans_one.size(); j += 3) {
      if (j + 2 >= ans_one.size()) break;
      cout << ans_one[j] + 1 << " " << ans_one[j + 1] + 1 << " "
           << ans_one[j + 2] + 1 << endl;
    }
  } else
    cout << -1;
  return 0;
}
