#include <bits/stdc++.h>
int main() {
  int h, w, i, j;
  char a[50][50];
  while (~scanf("%d%d", &h, &w)) {
    for (i = 0; i < h; i++) scanf("%s", a[i]);
    for (i = 0; i < h; i++)
      for (j = 0; j < w; j++)
        if (a[i][j] == '.') a[i][j] = '0';
    for (i = 0; i < h; i++)
      for (j = 0; j < w; j++)
        if (a[i][j] == '#') {
          if (a[i - 1][j - 1] != '#') a[i - 1][j - 1]++;
          if (a[i - 1][j] != '#') a[i - 1][j]++;
          if (a[i - 1][j + 1] != '#') a[i - 1][j + 1]++;
          if (a[i][j - 1] != '#') a[i][j - 1]++;
          if (a[i][j + 1] != '#') a[i][j + 1]++;
          if (a[i + 1][j - 1] != '#') a[i + 1][j - 1]++;
          if (a[i + 1][j] != '#') a[i + 1][j]++;
          if (a[i + 1][j + 1] != '#') a[i + 1][j + 1]++;
        }
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) printf("%c", a[i][j]);
      printf("\n");
    }
    memset(a, 0, sizeof(a));
  }
  return 0;
}
