#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){
  int H,W;
  cin >> H >> W;
  map<int, string> S;

  for(int i = 0; i < H; i++){
    cin >> S[i];
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      int count = 0;
      if(S[i][j] == "."){
        count = 0;
        for(int diffH = -1; diffH <= 1; diffH++){
          if(diffH + i < 0 || diffH + i >= H) continue;
          for(int diffW = -1; diffW <= 1; diffW++){
            if(diffW + j < 0 || diffW + j >= W) continue;
            count++;
          }
        }
        S[i][j] = count;
      }
    }
    cout << S[i];
  }

  return 0;
}
