#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, map[55][55];
  char ch;
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; ++i) {
    for (register int j = 1; j <= m; ++j) {
      cin >> ch;
      if (ch == '#') {
        map[i][j] = 1;
      }
    }
  }
  for (register int i = 1; i <= n; ++i) {
    for (register int j = 1; j <= m; ++j) {
      if (map[i][j]) {
        printf("#");
      } else {
        printf("%d", map[i - 1][j - 1] + map[i - 1][j] + map[i - 1][j + 1] +
                         map[i][j - 1] + map[i][j + 1] + map[i + 1][j - 1] +
                         map[i + 1][j] + map[i + 1][j + 1]);
      }
    }
    printf("\n");
  }
  return 0;
}
