#include <fstream>
using namespace std;
ifstream input("bit.in");
ofstream output("bit.out");
int n,m,c,now,ans[200][200];
char temp[200];
int main(void)
{
int i,j;
input>>n>>m;
c=n*m;
for (i=1;i<=n;i++)
{
input>>temp;
for (j=0;j<=m-1;j++)
{
if (temp[j]=='0')
ans[i][j+1]=1000;
if (temp[j]=='1')
c--;
}
}
now=0;
while (c>0)
{
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
if (ans[i][j]==now)
{
if (i-1>=1&&now+1<ans[i-1][j])
{
ans[i-1][j]=now+1;
c--;
}
if (i+1<=n&&now+1<ans[i+1][j])
{
ans[i+1][j]=now+1;
c--;
}
if (j-1>=1&&now+1<ans[i][j-1])
{
ans[i][j-1]=now+1;
c--;
}
if (j+1<=m&&now+1<ans[i][j+1])
{
ans[i][j+1]=now+1;
c--;
}
}
now++;
}
for (i=1;i<=n;i++)
{
for (j=1;j<=m;j++)
{
output<<ans[i][j];
if (j!=m)
output<<' ';
}
output<<endl;
}
input.close();
output.close();
return(0);
}