#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  string s[50];
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> s[i];
  int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        int v = 0;
        for (int k = 0; k < 8; k++) {
          int vh = i + dx[k], vw = j + dy[k];
          if (vh < 0 || w < vh) continue;
          if (vw < 0 || w < vw) continue;
          if (s[vh][vw] == '#') v++;
        }
        s[i][j] = v + '0';
      }
    }
  }
  for (int i = 0; i < h; i++) cout << s[i] << endl;
  return 0;
}
