#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  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++) {
      int c = 0;
      if (s[i][j] == '.') {
        for (int a = -1; a <= 1; a++) {
          for (int b = -1; b <= 1; b++) {
            if (s[i + a][j + b] == '#') c++;
          }
        }
        s[i][j] = c + '0';
      }
    }
  }
  for (int i = 0; i < h; i++) cout << s[i] << endl;
  ;
}
