#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char map[h + 2][w + 2];
  int out[h][w];
  int d[8][2] = {{1, 0}, {-1, 0}, {0, 1},  {0, -1},
                 {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
  for (int i = 1; i < h + 1; i++)
    for (int j = 1; j < w + 1; j++) cin >> map[i][j];
  for (int i = 1; i < h + 1; i++)
    for (int j = 1; j < w + 1; j++) {
      if (map[i][j] == '#')
        out[i - 1][j - 1] = -1;
      else {
        int count = 0;
        for (int r = 0; r < 8; r++)
          if (map[i + d[r][0]][j + d[r][1]] == '#') count++;
        out[i - 1][j - 1] = count;
      }
    }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (out[i][j] == -1)
        cout << "#";
      else
        cout << out[i][j];
    }
    cout << endl;
  }
  return 0;
}
