#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)

int main(){
  int dx[] = {1,1,0,-1,-1,-1,0,1};
  int dy[] = {0,1,1,1,0,-1,-1,-1};
   
  string S[60];
  
  int x, y;
  cin >> x >> y;
  
  rep(i,x) cin >> S[i];
  
  rep(i,x){
    rep(j,y){
      if(S[i][j] =='.'){
        int count = 0;
        rep(k,8){
          int x = i + dx[k];
          int y = j + dy[k];
          if(x >= 0 && y >= 0 && S[x][y] == '#') count ++;
        }
        S[i][j] = '0' + count;
      }
    }
  }
  rep(i,x) cout << S[i] << endl;
}