#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int n,m,e[1010][1010];
inline int read(){
int f=0,x=0;
char ch=getchar();
while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return f?-x:x;
}
signed main(){
n=read();m=read();
for(int i=1;i<=n;++i){
int u=read(),v=read();
e[u][v]=e[v][u]=1;
}
for(int k=1;k<=n;++k)
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
e[i][j] |= e[i][k] & e[k][j];
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j)
printf("%d ",e[i][j]);
printf("\n");
}
return 0;
}