int main()
{
int n, m;
cin >> n >> m;
vector<vector<int>>hehe(n+2, vector<int>(m+2, -1)),ans(n+2, vector<int>(m+2, 1));
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
cin >> hehe[i][j];
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
int tmp = 1;
if (hehe[i][j] == hehe[i][j+tmp] && hehe[i][j] == hehe[i][j-tmp])
{
while (hehe[i][j] == hehe[i][j + tmp])
{
ans[i][j + tmp] = 0;
tmp++;
}
tmp = 1;
while (hehe[i][j] == hehe[i][j - tmp])
{
ans[i][j - tmp] = 0;
tmp++;
}
ans[i][j] = 0;
}
tmp = 1;
if (hehe[i][j] == hehe[i + tmp][j] && hehe[i][j] == hehe[i - tmp][j])
{
while (hehe[i + tmp][j] == hehe[i][j])
{
ans[i + tmp][j] = 0;
tmp++;
}
tmp = 1;
while (hehe[i - tmp][j] == hehe[i][j])
{
ans[i - tmp][j] = 0;
tmp++;
}
ans[i][j] = 0;
}
}
}
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
if (ans[i][j] == 0)
cout << 0 << " ";
else
cout << hehe[i][j]<<" ";
cout << endl;
}
}