#include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<queue> #include<algorithm> using namespace std; int vis[50]; int fa[50]; int num[50]; int find(int x) { return fa[x]==x?x:find(fa[x]); } void bincha(int x,int y) { int fx=find(x); int fy=find(y); if(fx!=fy) { fa[fx]=fa[fy]; num[fy]+=num[fx]; } } int main() { int n,m; int i,j,k; int f,t; int x,y; while(scanf("%d%d",&n,&m)!=EOF) { memset(vis,0,sizeof(vis)); int ok=1; for(i=0;i<=n;i++) { fa[i]=i; num[i]=1; } while(m--) { scanf("%d%d",&x,&y); vis[x]=vis[y]=2; bincha(x,y); } for(i=1;i<=n;i++) { int fi=find(i); if(num[fi]>3) { ok=0; break; } } if(ok==0) { printf("-1 "); continue; } for(i=1;i<=n;i++) { if(find(i)==i&&vis[i]==2) { //printf("%d %d.... ",i,vis[i]); printf("%d",i); int coun=0; for(j=1;j<=n;j++) { if(find(j)==i&&j!=i) { printf(" %d",j); coun++; } } //printf(" ......%d %d ",i,coun); if(coun==1) { for(j=1;j<=n;j++) { if(vis[j]==0) { vis[j]=1; printf(" %d",j); break; } } } printf(" "); } } // printf("dddddddddddd "); int cnt=0; for(i=1;i<=n;i++) { if(vis[i]==0) { printf("%d",i); cnt++; if(cnt%3==0) printf(" "); else printf(" "); } } } return 0; }