#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;
constexpr ll kMod = 1e9 + 7;
ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
ll solve(const vector<string>& S, ll H, ll W, ll h, ll w) {
  if (S[h][w] == '#') {
    return -1;
  }
  ll sum = 0;
  for (ll(i) = (h - 1); (i) < (h + 2); (i)++) {
    for (ll(j) = (w - 1); (j) < (w + 2); (j)++) {
      if (i == h && j == w) {
        continue;
      }
      if (i < 0 || H < i || j < 0 || W < j) {
        continue;
      }
      if (S[i][j] == '#') {
        sum++;
      }
    }
  }
  return sum;
}
int main() {
  init();
  ll H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (ll(i) = (0); (i) < (H); (i)++) {
    string s;
    cin >> s;
    S[i] = s;
  }
  for (ll(h) = (0); (h) < (H); (h)++) {
    for (ll(w) = (0); (w) < (W); (w)++) {
      ll s = solve(S, H, W, h, w);
      if (s == -1) {
        cout << "#";
      } else {
        cout << s;
      }
    }
    cout << endl;
  }
  return 0;
}
