#include <bits/stdc++.h>
int main() {
  int h, w;
  char mine[50][50];
  scanf("%d %d", &h, &w);
  for (int i = 0; i < h; i++) scanf("%s", mine[i]);
  int dir_h[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  int dir_w[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  char num[50][50];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) num[i][j] = '0';
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (mine[i][j] == '#') num[i][j] = '#';
      for (int k = 0; k < 8; k++)
        if (mine[i][j] == '.' && mine[i + dir_h[k]][j + dir_w[k]] == '#' &&
            i + dir_h[k] >= 0 && i + dir_h[k] <= h && j + dir_w[k] >= 0 &&
            j + dir_w[k] <= w)
          num[i][j]++;
    }
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      printf("%c", num[i][j]);
      if (j == w - 1) printf("\n");
    }
}
