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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  for(int i=0;i<H;i++){
    cin >> S[i];
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j] == '.'){
        int cnt = 0;
        for(int k=i-1;k<=i+1;k++){
          for(int l=j-1;l<=j+1;l++){
            if(0 <= k && k < H && 0 <= l && l <= W && S[k][l] == '#'){
              cnt++;
            }
          }
        }
        S[i][j] = (char)(cnt+'0');
      }
    }
    cout << S[i] << endl;
  }
}