#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int h, w;
  cin >> h, w;
  vector<vector<char>> coordinate(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> coordinate[i][j];
    }
  }
  const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int num = 0;
      if (coordinate[i][j] == '#') {
        cout << '#';
        continue;
      } else {
        for (int k = 0; k < 8; k++) {
          int ni = i + dy[k];
          int nj = j + dx[k];
          if (ni < 0 || ni >= h) continue;
          if (nj < 0 || nj >= w) continue;
          if (coordinate[ni][nj] == '#') {
            num++;
          }
        }
        cout << num;
      }
    }
  }
}
