#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
long long fact(long long n) {
  long long res = 1;
  for (long long i = 2; i <= n; ++i) res = res * i;
  return res;
}
long long nCr(long long n, long long r) {
  return (fact(n) / fact(n - r) * fact(r));
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
const int inf = 1 << 30;
int H, W;
string S[50];
char ans[50][50];
char bombSearch(int h, int w) {
  int res = 0;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      int nh = h + i, nw = w + j;
      if (h < 0 || h >= H) continue;
      if (w < 0 || w >= W) continue;
      if (S[nh][nw] == '#') res++;
    }
  }
  return res + '0';
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  for (int i = 0; i < (int)(H); ++i) cin >> S[i];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        ans[i][j] = bombSearch(i, j);
      } else {
        ans[i][j] = '#';
      }
    }
  }
  for (int i = 0; i < (int)(H); ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
