#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] == '.') {
        s[i][j] = 0;
        for (int k = -1; k <= 1; k++) {
          for (int l = -1; l <= 1; l++) {
            int h = i + k, w = j + l;
            if (0 <= h && h < H && 0 <= w && w < W) {
              if (s[h][i] == '#') s[i][j]++;
            }
          }
        }
      }
    }
  for (int i = 0; i < (H); i++) cout << s[i] << endl;
}
