// package csp;
import java.util.*;
import java.io.*;
public class Main {
public static int a[][]=new int [40][40];
public static int f[][]=new int [40][40];
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner cin=new Scanner(new BufferedInputStream(System.in));
int n=cin.nextInt(),m=cin.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
a[i][j]=cin.nextInt();
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j-1]==a[i][j]&&a[i][j+1]==a[i][j]) {
f[i][j]=1;
f[i][j-1]=1;
f[i][j+1]=1;
}
if(a[i-1][j]==a[i][j]&&a[i+1][j]==a[i][j]) {
f[i-1][j]=1;
f[i][j]=1;
f[i+1][j]=1;
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(f[i][j]==1) {
System.out.print(0+" ");
}else {
System.out.print(a[i][j]+" ");
}
}
System.out.println();
}
}
}