#include <bits/stdc++.h>
int chkp[1129];
int chk[50];
class t {
 public:
  int a, b;
};
t s[1129];
int ans[1129][3], k = 0, m;
int main() {
  int n;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) scanf("%d%d", &s[i].a, &s[i].b);
  int n2 = 1;
  for (int i = 0; i < m; i++) {
    if (chk[s[i].a] == 0 && chk[s[i].b] == 0) {
      if (k >= n / 3) {
        printf("-1");
        return 0;
      }
      chk[s[i].a] = k + 1;
      ans[k][0] = s[i].a;
      chk[s[i].b] = k + 1;
      ans[k][1] = s[i].b;
      k++;
    } else if (chk[s[i].a] == 0) {
      if (ans[chk[s[i].b] - 1][2] == 0) {
        ans[chk[s[i].b] - 1][2] = s[i].a;
        chk[s[i].a] = chk[s[i].b];
      } else {
        printf("-1");
        return 0;
      }
    } else if (chk[s[i].b] == 0) {
      if (ans[chk[s[i].a] - 1][2] == 0) {
        ans[chk[s[i].a] - 1][2] = s[i].b;
        chk[s[i].b] = chk[s[i].a];
      } else {
        printf("-1");
        return 0;
      }
    } else if (chk[s[i].a] != chk[s[i].b]) {
      printf("-1");
      return 0;
    }
  }
  int u = 1;
  for (int i = 0; i < n / 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (ans[i][j] == 0) {
        while (chk[u] && u <= n) {
          u++;
        }
        ans[i][j] = u;
        if (u > n) {
          printf("-1");
          return 0;
        }
        chk[u] = 1;
      }
    }
  }
  for (int i = 0; i < n / 3; i++) {
    printf("%d %d %d\n", ans[i][0], ans[i][1], ans[i][2]);
  }
  return 0;
}
