#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long double pi = acos(-1.0);
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  long long h, w;
  cin >> h >> w;
  char mp[h][w];
  long long ans[h][w];
  for (long long i = 0; i < (long long)(h); i++)
    for (long long j = 0; j < (long long)(w); j++) ans[i][j] = 0;
  for (long long i = 0; i < (long long)(h); i++)
    for (long long j = 0; j < (long long)(w); j++) cin >> mp[i][j];
  for (long long i = 0; i < (long long)(h); i++)
    for (long long j = 0; j < (long long)(w); j++) {
      if (mp[i][j] == '#') {
        ans[i][j] = -INF;
        if (0 <= j + 1 && j + 1 < w) ans[i][j + 1]++;
        if (0 <= j - 1 && j - 1 < w) ans[i][j - 1]++;
        if (0 <= i + 1 && i + 1 < h) ans[i + 1][j]++;
        if (0 <= j - 1 && j - 1 < w && 0 <= i + 1 && i + 1 < h)
          ans[i + 1][j - 1]++;
        if (0 <= j + 1 && j + 1 < w && 0 <= i + 1 && i + 1 < h)
          ans[i + 1][j + 1]++;
        if (0 <= i - 1 && i - 1 < w) ans[i - 1][j]++;
        if (0 <= j + 1 && j + 1 < w && 0 <= i - 1 && i - 1 < h)
          ans[i - 1][j + 1]++;
        if (0 <= j - 1 && j - 1 < w && 0 <= i - 1 && i - 1 < h)
          ans[i - 1][j - 1]++;
      }
    }
  for (long long i = 0; i < (long long)(h); i++) {
    for (long long j = 0; j < (long long)(w); j++) {
      if (ans[i][j] < 0)
        cout << '#';
      else
        cout << to_string(ans[i][j]);
    }
    cout << endl;
  }
  return 0;
}
