#include <bits/stdc++.h>
using namespace std;
int in[50];
bool visited[50] = {false};
vector<vector<int> > v(50);
vector<vector<int> > output(50);
int main(int argc, char const *argv[]) {
  int n, m, a, b;
  cin >> n >> m;
  memset(in, 0, sizeof(in));
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
    in[a]++;
    in[b]++;
  }
  set<int> s;
  int k = 0;
  for (int i = 1; i <= n; i++)
    if (in[i] == 0) s.insert(i);
  for (int i = 1; i <= n; i++) {
    if (in[i] != 0 && visited[i] == false) {
      int members = 0;
      visited[i] = true;
      queue<int> q;
      q.push(i);
      while (!q.empty()) {
        int top = q.front();
        output[k].push_back(top);
        members++;
        for (int x = 0; x < v[top].size(); x++) {
          if (visited[v[top][x]] == false) {
            visited[v[top][x]] = true;
            q.push(v[top][x]);
          }
        }
        q.pop();
      }
      if (members == 1) {
        if (s.size() < 2) {
          cout << "-1\n";
          return 0;
        }
        output[k].push_back(*s.begin());
        s.erase(s.begin());
        output[k].push_back(*s.begin());
        s.erase(s.begin());
      } else if (members == 2) {
        if (s.size() < 1) {
          cout << "-1\n";
          return 0;
        }
        output[k].push_back(*s.begin());
        s.erase(s.begin());
      }
      if (members > 3) {
        cout << "-1";
        return 0;
      }
      k++;
    }
  }
  int no = 0;
  for (int i = 0; i < output.size(); i++) {
    if (output[i].size() != 0) {
      for (int j = 0; j < 3; j++) {
        cout << output[i][j] << " ";
      }
      cout << "\n";
    }
  }
  while (!s.empty()) {
    no++;
    cout << *s.begin() << " ";
    s.erase(s.begin());
    if (no % 3 == 0) {
      cout << "\n";
    }
  }
  return 0;
}
