#include <iostream>
using namespace std;
int n,m,i,j,k,a[101][101];
int main()
{
cin>>n>>m;
for(k=1;k<=m;k++)
{
cin>>i>>j;
a[i][j]=1;
}
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(a[i][j]==0) a[i][j]=a[i][k]*a[k][j];
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
cout<<a[i][j]<<' ';
cout<<'\n';
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IG4sbSxpLGosayxhWzEwMV1bMTAxXTsKaW50IG1haW4oKQp7CiAgICBjaW4+Pm4+Pm07CiAgICBmb3Ioaz0xO2s8PW07aysrKQogICAgewogICAgICAgIGNpbj4+aT4+ajsKICAgICAgICBhW2ldW2pdPTE7CiAgICB9CiAgICBmb3Ioaz0xO2s8PW47aysrKQogICAgICAgIGZvcihpPTE7aTw9bjtpKyspCiAgICAgICAgICAgIGZvcihqPTE7ajw9bjtqKyspCiAgICAgICAgICAgICAgICBpZihhW2ldW2pdPT0wKSBhW2ldW2pdPWFbaV1ba10qYVtrXVtqXTsKICAgIGZvcihpPTE7aTw9bjtpKyspCiAgICB7CiAgICAgICAgZm9yKGo9MTtqPD1uO2orKykKICAgICAgICAgICAgY291dDw8YVtpXVtqXTw8JyAnOwogICAgICAgIGNvdXQ8PCdcbic7CiAgICB9CiAgICByZXR1cm4gMDsKCn0=