#include <bits/stdc++.h>
using namespace std;
struct Fast {
  Fast() {
    std::cin.tie(0);
    ios::sync_with_stdio(0);
  }
} fast;
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;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
const long long inf = 1e9 + 7;
signed main(void) {
  const long long dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  const long long dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  long long w, h, nx, ny, cnt;
  cin >> h >> w;
  array<string, 100> v;
  for (long long i = 0; i < (long long)(h); ++i) {
    cin >> v[i];
  }
  for (long long i = 0; i < (long long)(h); ++i) {
    for (long long j = 0; j < (long long)(w); ++j) {
      if (v[i][j] == '#') {
        continue;
      }
      cnt = 0;
      for (long long k = 0; k < (long long)(8); ++k) {
        nx = i + dx[k];
        ny = j + dy[k];
        if (v[nx][ny] == '#') {
          cnt++;
        }
      }
      v[i][j] = char(cnt + '0');
    }
  }
  for (long long i = 0; i < (long long)(h); ++i) {
    cout << v[i] << endl;
  }
  return 0;
}
