#include <bits/stdc++.h>
using namespace std;
class disjoint {
 public:
  int parents[49];
  int group[49];
  int n;
  disjoint(int num) {
    n = num + 1;
    for (int i = 1; i < n; i++) {
      parents[i] = i;
      group[i] = 1;
    }
  }
  int parent(int a) { return parents[a]; }
  int merge(int p, int c) {
    if (parents[p] == parents[c]) {
      return -1;
    }
    while (parent(p) != p) {
      p = parent(p);
    }
    parents[c] = p;
    group[p]++;
    group[c] = 0;
    return group[p];
  }
  void print() {
    cout << "parents\n";
    for (int i = 1; i < n; i++) {
      cout << i << " is child of " << parents[i] << endl;
      ;
    }
    cout << "groupSize\n";
    for (int i = 1; i < n; i++) {
      cout << i << " has a group of size " << group[i] << endl;
    }
  }
  int getSum() {
    int sum = 0;
    int size[4];
    size[0] = 0;
    size[1] = 0;
    size[2] = 0;
    size[3] = 0;
    for (int i = 1; i < n; i++) {
      if (group[i] > 3) {
        return -1;
      }
      size[group[i]]++;
    }
    size[1] -= size[2];
    size[2] = 0;
    if (size[1] < 0) {
      return -1;
    } else {
      return size[1];
    }
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  disjoint d(n);
  vector<int> ones;
  vector<int> twos;
  vector<int> threes;
  int from[m], to[m];
  for (int i = 0; i < m; i++) {
    cin >> from[i] >> to[i];
    d.merge(from[i], to[i]);
  }
  if (d.getSum() % 3 == 0) {
    for (int i = 1; i < d.n; i++) {
      if (d.group[i] == 3) {
        for (int j = 1; j < d.n; j++) {
          if (d.parents[i] == d.parents[j]) {
            threes.push_back(j);
          }
        }
      } else if (d.group[i] == 2) {
        for (int j = 1; j < d.n; j++) {
          if (d.parents[i] == d.parents[j]) {
            twos.push_back(j);
          }
        }
      } else if (d.group[i] == 1) {
        ones.push_back(i);
      }
    }
    while (twos.size() > 0) {
      int temp = twos.back();
      twos.pop_back();
      cout << temp << " ";
      temp = twos.back();
      twos.pop_back();
      cout << temp << " ";
      temp = ones.back();
      ones.pop_back();
      cout << temp << "\n";
    }
    while (ones.size() > 0) {
      int temp = ones.back();
      ones.pop_back();
      cout << temp << " ";
      temp = ones.back();
      ones.pop_back();
      cout << temp << " ";
      temp = ones.back();
      ones.pop_back();
      cout << temp << "\n";
    }
    while (threes.size() > 0) {
      int temp = threes.back();
      threes.pop_back();
      cout << temp << " ";
      temp = threes.back();
      threes.pop_back();
      cout << temp << " ";
      temp = threes.back();
      threes.pop_back();
      cout << temp << "\n";
    }
  } else {
    cout << -1;
  }
  return 0;
}
