#include <bits/stdc++.h>
using namespace std;
int r, c;
char mapp[1000][1000];
int dx[8] = {-1, 1, -1, 1, 1, -1, 0, 0};
int dy[8] = {0, 1, 1, -1, 0, -1, -1, 1};
int sweep(int x, int y) {
  int ans = 0;
  for (int i = 0; i < 8; ++i) {
    int newx = dx[i] + x;
    int newy = dy[i] + y;
    if (newx > 0 && newx <= r && newy > 0 && newy <= c) {
      if (mapp[newx][newy] == '#') ++ans;
    }
  }
  return ans;
}
int main() {
  scanf("%d%d", &r, &c);
  for (int i = 1; i <= r; ++i) {
    for (int j = 1; j <= c; ++j) {
      cin >> mapp[i][j];
    }
  }
  for (int i = 1; i <= r; ++i) {
    for (int j = 1; j <= c; ++j) {
      if (mapp[i][j] != '#') mapp[i][j] = sweep(i, j);
    }
  }
  for (int i = 1; i <= r; ++i) {
    for (int j = 1; j <= c; ++j) {
      printf("%c", mapp[i][j]);
    }
    printf("\n");
  }
}
