#include <bits/stdc++.h>
using namespace std;
int h, w;
vector<string> s(h);
int Minesweeper(int x, int y) {
  int count = 0;
  for (int i = max(y - 1, 0); i <= min(y + 1, h - 1); i++) {
    for (int j = max(x - 1, 0); j <= min(x + 1, w - 1); j++) {
      if (s[i][j] == '#') count++;
    }
  }
  return count;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> s[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++)
      if (s[i][j] == '.') {
        s[i][j] = (char)(Minesweeper(i, j) + '0');
      }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << s[i][j];
    }
    cout << endl;
  }
}
