#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
int main() {
  int H , W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i,H)cin >> S[i];
  
  rep(i,H)rep(j,W){
    if(S[i][j] == '.'){
      S[i][j] = '0';
      for(int dx = -1;dx <= 1;dx++){
        for(int dy = -1;dy <= 1;dy++){
          int x = i + dx,y = j + dy;
          if(0 <= x&& x < H && 0 <= y && y < W){
            if(S[x][y] == '#'){
              S[i][j] ++;
            }
          }
        }
      }
    }
  }
  rep(i,H)cout << S[i] << endl;
}