#include <iostream>
#include <string>
using namespace std;

int main(){
  int H, W;
  cin >> H >> W;
  char s[H][W];
  int c[H][W];  
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      cin >> s[i][j];
      c[i][j] = 0;        
    }
  }
  int deltaArrayM[8] = {1,0,-1,0,1,-1,1,-1};
  int deltaArrayN[8] = {0,1,0,-1,1,-1,-1,1};
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (s[i][j] == '#') {
        for (int k = 0 ; k < 8; ++k){
          int deltaM = i + deltaArrayM[k];
          int deltaN = j + deltaArrayN[k];
          if ((deltaM < 0) || (deltaM > H) || (deltaN < 0) || (deltaN > W)) {
            continue;
          if (s[deltaM][deltaN] != '#') {
            c[deltaM][deltaN] += 1;
          }
        }
      }     
    }
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (s[i][j] == '#') {   
        cout << "#";
      }
      else {
        cout << c[i][j];
    }
    cout << "\n";
    }
  }
}
  
  