#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int R,C; cin >> R >> C;
vector<string> V(R);
for (auto&v:V) cin >> v;
for (int r=0; r<R;++r)for(int c=0;c<C;++c) {
if (V[r][c]!='#'){V[r][c]='0';
for (int dr=-1; dr<=1;++dr)for(int dc=-1;dc<=1;++dc) {
if(r+dr>=0&&r+dr<R&&c+dc>=0&&c+dc<C&&V[r+dr][c+dc]=='#')V[r][c]++;
}
}
}
for(auto&v:V) cout << v << '\n';
}