#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> board(h);
  for (int i = 0; i < h; i++) {
    cin >> board[i];
  }
  const int x[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  const int y[8] = {1, 1, 1, 0, 0, -1, -1, -1};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (board[i][j] == '#') continue;
      int cnt = 0;
      for (int k = 0; k < 8; ++k) {
        const int iy = i + y[k];
        const int jx = j + x[k];
        if (iy < 0 || h <= iy) continue;
        if (jx < 0 || w <= jx) continue;
        if (board[iy][jx] == '#') cnt++;
      }
      board[i][j] = char(cnt + '0');
    }
  }
  for (int i = 0; i < h; i++) cout << board[i] << endl;
}
