#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H + 2, vector<char>(W + 2, '.'));
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> S[i][j];
    }
  }
  int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
  int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
  for (int i = 1; i < H; i++) {
    for (int j = 1; j <= W; j++) {
      if (S[i][j] == '#') {
        cout << S[i][j];
      } else {
        int res = 0;
        for (int k = 0; k < 8; k++) {
          if (S[i + dx[k]][j + dy[k]] == '#') {
            res++;
          }
        }
        cout << res;
      }
    }
    cout << endl;
  }
}
