#include <bits/stdc++.h>
using namespace std;
int n,m, head[1005], du[1005], nexts[100005], ver[100005], tot = 0, tu[1005][1005], tmp[100005];
void add(int a,int b) {
tu[a][b] = 1;tu[b][a] = 1;
nexts[++tot] = head[a];head[a] = tot;ver[tot] = b;
nexts[++tot] = head[b];head[b] = tot;ver[tot] = a;
du[a]++;du[b]++;
}
void init() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; i++) {
int a,b;
scanf("%d%d", &a,&b);
add(a,b);
}
}
void print() {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
printf("%d ", tu[i][j]);
}
printf("\n");
}
for(int i = 1; i <= n; i++) {
printf("%d ", du[i]);
int cnt = 0;
for(int j = head[i]; j; j = nexts[j]) {
tmp[++cnt] = ver[j];
}
if(cnt > 0) {
sort(tmp+1, tmp+1+cnt);
for(int j = 1; j <= cnt; j++) printf("%d ", tmp[j]);
}
else printf("0");
printf("\n");
}
}
int main() {
init();
print();
return 0;
}