#include<bits/stdc++.h>
using namespace std;
const int N = 1e2+10;
int n,m;
//存地图和雷分布图
int a[N][N], b[N][N];
//拿到周边的雷数
int get(int x, int y){
int ans = 0;
for(int i = x - 1; i<= x + 1; i++){
for(int j = y - 1; j <= y + 1; j++){
ans += a[i][j];
}
}
return ans;
}
int main(){
cin>>n>>m;
//这里1开始是因为get中要减1
for(int i = 1; i<= n; i++){
for(int j = 1; j <= m; j++){
cin>>a[i][j];
}
}
//更新每个位置的雷数量
for(int i = 1; i<= n; i++){
for(int j = 1; j <= m; j++){
if(a[i][j]==1) b[i][j] = 9;
else
b[i][j] = get(i,j);
}
}
//输出b的雷分布图
for(int i = 1; i<= n; i++){
for(int j = 1; j <= m; j++){
cout<<b[i][j]<<' ';
}
cout<<endl;
}
return 0;
}