#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
int h, k;
int g[maxn][maxn];
inline bool check(int x, int y) {
  if (x >= h || x <= 0) return 0;
  if (y >= k || y <= 0) return 0;
  return 1;
}
int cx[] = {0, 1, 1, 1, 0, 0, -1, -1, -1};
int cy[] = {0, -1, 0, 1, -1, 1, -1, 0, 1};
int main() {
  cin >> h >> k;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= k; j++) {
      char x = getchar();
      while (x != '.' && x != '#') x = getchar();
      if (x == '#') g[i][j] = -1;
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= k; j++) {
      if (g[i][j] == -1) continue;
      for (int l = 1; l <= 8; l++)
        if (check(i + cx[l], j + cy[l])) {
          if (g[i + cx[l]][j + cy[l]] == -1) g[i][j]++;
        }
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= k; j++) {
      if (g[i][j] == -1) {
        printf("#");
        continue;
      }
      printf("%d", g[i][j]);
    }
    printf("\n");
  }
  return 0;
}
