#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll isPrime(ll n) {
  if (n < 2) {
    return 0;
  }
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}
vector<ll> getDivisor(ll n) {
  vector<ll> v;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
      if (i != n / i) {
        v.push_back(n / i);
      }
    }
  }
  sort(v.begin(), v.end());
  return v;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(15);
  srand((unsigned)time(NULL));
  ll h, w;
  cin >> h >> w;
  string a, b;
  for (ll i = 0; i < (ll)(h); i++) {
    cin >> a;
    b += a;
  }
  ll n = h * w;
  for (ll i = 0; i < (ll)(n); i++) {
    if (i != 0 && i % w == 0) cout << endl;
    if (b.at(i) == '#')
      cout << '#';
    else {
      ll now = 0;
      if (i == 0) {
        if (b.at(i + 1) == '#') now++;
        if (b.at(i + w) == '#') now++;
        if (b.at(i + w + 1) == '#') now++;
        cout << now;
        continue;
      } else if (i == w - 1) {
        if (b.at(i - 1) == '#') now++;
        if (b.at(i + w - 1) == '#') now++;
        if (b.at(i + w) == '#') now++;
        cout << now;
        continue;
      } else if (i == w * (h - 1)) {
        if (b.at(i - w) == '#') now++;
        if (b.at(i - w + 1) == '#') now++;
        if (b.at(i + 1) == '#') now++;
        cout << now;
      } else if (i == w * h - 1) {
        if (b.at(i - 1) == '#') now++;
        if (b.at(i - w - 1) == '#') now++;
        if (b.at(i - w) == '#') now++;
        cout << now;
      } else if (i < w) {
        if (b.at(i - 1) == '#') now++;
        if (b.at(i + 1) == '#') now++;
        if (b.at(i + w - 1) == '#') now++;
        if (b.at(i + w) == '#') now++;
        if (b.at(i + w + 1) == '#') now++;
        cout << now;
      } else if (i % w == 0) {
        if (b.at(i - w) == '#') now++;
        if (b.at(i - w + 1) == '#') now++;
        if (b.at(i + 1) == '#') now++;
        if (b.at(i + w) == '#') now++;
        if (b.at(i + w + 1) == '#') now++;
        cout << now;
      } else if ((i + 1) % w == 0) {
        if (b.at(i - 1) == '#') now++;
        if (b.at(i - w - 1) == '#') now++;
        if (b.at(i - w) == '#') now++;
        if (b.at(i + w) == '#') now++;
        if (b.at(i + w - 1) == '#') now++;
        cout << now;
      } else if (i >= (h - 1) * w) {
        if (b.at(i - w) == '#') now++;
        if (b.at(i - w - 1) == '#') now++;
        if (b.at(i - w + 1) == '#') now++;
        if (b.at(i + 1) == '#') now++;
        if (b.at(i - 1) == '#') now++;
        cout << now;
      } else {
        if (b.at(i - w - 1) == '#') now++;
        if (b.at(i - w) == '#') now++;
        if (b.at(i - w + 1) == '#') now++;
        if (b.at(i - 1) == '#') now++;
        if (b.at(i + 1) == '#') now++;
        if (b.at(i + w - 1) == '#') now++;
        if (b.at(i + w) == '#') now++;
        if (b.at(i + w + 1) == '#') now++;
        cout << now;
      }
    }
  }
  return 0;
}
