#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
using ll = long long;
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
int main() {
  int H, W;
  cin >> H >> W;
  string s[50];
  for (int i = 0, i_len = (H); i < i_len; ++i) cin >> s[i];
  int X[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  int Y[8] = {1, 1, 1, 0, 0, -1, -1, -1};
  for (int i = 0, i_len = (H); i < i_len; ++i)
    for (int j = 0, j_len = (W); j < j_len; ++j) {
      if (s[i][j] == '#')
        continue;
      else {
        int count = 0;
        for (int d = 0; d < 8; d++) {
          int ni = i + X[d];
          int nj = j + Y[d];
          if (ni < 0 || ni > H || nj < 0 || nj > W) continue;
          if (s[ni][nj] == '#') count++;
        }
        s[i][j] = '0' + count;
      }
    }
  for (int i = 0, i_len = (H); i < i_len; ++i) cout << s[i] << endl;
}
