#include <bits/stdc++.h>
using namespace std;
struct well {
  long long int aa, bb, cc, dd;
};
long long int ans[1000][1000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k = 0, x = 0, y = 0, z = 0, c = 0, mini = 0,
                      anss = LLONG_MIN, last, sum = 0;
  long long int n, a, m = 0, b, first, c0, d0;
  cin >> n >> a;
  char A[n + 5][a + 5];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= a; j++) cin >> A[i][j];
  for (i = 1; i <= a; i++) {
    for (j = 1; j <= a; j++) {
      if (A[i][j] == '#') continue;
      if (A[i - 1][j] == '#') ans[i][j] += 1;
      if (A[i - 1][j + 1] == '#') ans[i][j] += 1;
      if (A[i - 1][j - 1] == '#') ans[i][j] += 1;
      if (A[i][j + 1] == '#') ans[i][j] += 1;
      if (A[i][j - 1] == '#') ans[i][j] += 1;
      if (A[i + 1][j] == '#') ans[i][j] += 1;
      if (A[i + 1][j + 1] == '#') ans[i][j] += 1;
      if (A[i + 1][j - 1] == '#') ans[i][j] += 1;
    }
  }
  for (i = 1; i <= n; i++, cout << endl)
    for (j = 1; j <= a; j++)
      if (A[i][j] == '#')
        cout << "#";
      else
        cout << ans[i][j];
}
