#include <bits/stdc++.h>
using namespace std;
int sumDigits(int n) {
  int s;
  while (n > 0) {
    s += n % 10;
    n /= 10;
  }
  return s;
}
int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
int main() {
  int H, W;
  cin >> H >> W;
  string S[50];
  for (int i = 0; i < (H); i++) cin >> S[i];
  const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      if (S[i][j] == '#') continue;
      int num = 0;
      for (int k = 0; k < (8); k++) {
        int x = j + dx[k];
        int y = i + dy[k];
        if (x < 0 || W <= x) continue;
        if (y < 0 || H <= y) continue;
        if (S[y][x] == '#') num++;
      }
      cout << num << endl;
      S[i][j] = char(num + '0');
    }
  }
  for (int i = 0; i < (H); i++) cout << S[i] << endl;
}
