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