#include <bits/stdc++.h>
using namespace std;
int size[55], father[55];
int findroot(int x) {
  int root;
  for (root = x; father[root] != -1; root = father[root])
    ;
  int i;
  for (; father[x] != -1;) {
    i = father[x];
    father[x] = root;
    x = i;
  }
  return root;
}
void u(int x, int y) {
  int xx = findroot(x);
  int yy = findroot(y);
  if (xx == yy) return;
  if (size[xx] > size[yy]) swap(xx, yy);
  father[xx] = yy;
  size[yy] += size[xx];
}
vector<int> v[48];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int i;
  for (i = 0; i < n; i++) {
    size[i] = 1;
    father[i] = -1;
  }
  int x, y;
  for (i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    x--;
    y--;
    u(x, y);
  }
  int x1 = 0, x2 = 0, x3 = 0;
  for (i = 0; i < n; i++) {
    if (father[i] != -1) continue;
    if (size[i] > 3) {
      printf("-1\n");
      return 0;
    } else if (size[i] == 1)
      x1++;
    else if (size[i] == 2)
      x2++;
    else if (size[i] == 3)
      x3++;
  }
  if (x2 > x1) {
    printf("-1\n");
    return 0;
  }
  for (i = 0; i < n; i++) {
    v[findroot(i)].push_back(i + 1);
    if (father[i] != -1) {
      size[i] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    if (father[i] != -1) continue;
    if (size[i] == 3) {
      printf("%d %d %d\n", v[i][0], v[i][1], v[i][2]);
      size[i] = 0;
    } else if (size[i] == 2) {
      int j;
      for (j = 0; j < n; j++) {
        if (size[j] == 1) {
          size[j] = 0;
          size[i] = 0;
          printf("%d %d %d\n", v[j][0], v[i][0], v[i][1]);
          break;
        }
      }
    }
  }
  for (i = 0; i < n; i++) {
    if (size[i] == 1) {
      int j, k;
      for (j = 0; j < n; j++) {
        if ((size[j] == 1) && (j != i)) {
          for (k = 0; k < n; k++) {
            if ((size[k] == 1) && (j != k) && (k != i)) {
              size[i] = 0;
              size[j] = 0;
              size[k] = 0;
              printf("%d %d %d\n", v[i][0], v[j][0], v[k][0]);
              break;
            }
          }
          if (size[i] == 0) break;
        }
      }
    }
  }
  return 0;
}
