#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  int i, j, count = 0, p, q;
  cin >> h >> w;
  char s[h + 1][w + 1];
  for (i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        cout << '#';
      } else {
        for (p = -1; p <= 1; p++) {
          for (q = -1; q <= 1; q++) {
            if (s[i + p][j + q] == '#') {
              count++;
            }
          }
        }
        cout << count;
        count = 0;
      }
    }
    cout << "\n";
  }
  return 0;
}
