#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int h, w;
  cin >> h >> w;
  char dummy[2];
  gets(dummy);
  char g[100][100];
  for (int i = 0; i < h; ++i) gets(g[i]);
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) {
      if (g[i][j] == '#')
        continue;
      else {
        const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
        const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
        char num = '0';
        for (int d = 0; d < 8; ++d) {
          int x = i + dx[d];
          int y = j + dy[d];
          if (x < 0 || x >= h || y < 0 || y >= w)
            continue;
          else if (g[x][y] == '#')
            num++;
        }
        g[i][j] = num;
      }
    }
  for (int i = 0; i < h; i++) {
    cout << g[i] << "\n";
  }
  return 0;
}
