#include <bits/stdc++.h>
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long m, long long n) {
  if ((0 == m) || (0 == n)) return 0;
  return ((m / gcd(m, n)) * n);
}
long long llpow(long long x, long long y) {
  long long ans = 1;
  for (int i = 0, i_len = (y); i < i_len; ++i) ans *= x;
  return ans;
}
long long llmin(long long x, long long y) { return x < y ? x : y; }
long long llmax(long long x, long long y) { return x > y ? x : y; }
unsigned GetDigit(unsigned num) { return to_string(num).length(); }
template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v) {
  return (c.end() != std::find(c.begin(), c.end(), v));
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
long long nCr(int n, int r) {
  if (n == r or n == 0) return 1;
  if (n < r) return 0;
  if (r == 1) return n;
  return nCr(n - 1, r - 1) + nCr(n - 1, r);
}
int main() {
  int H, W;
  cin >> H >> W;
  char S[H][W];
  for (int i = 0, i_len = (H); i < i_len; ++i)
    for (int j = 0, j_len = (W); j < j_len; ++j) cin >> S[i][j];
  vector<string> ans(W);
  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] == '#') {
        ans[i].push_back('#');
        continue;
      }
      int cnt = 0;
      for (int k = 0, k_len = (8); k < k_len; ++k) {
        int next_x = i + dx8[k];
        int next_y = j + dy8[k];
        if (next_x < 0 || next_x >= W || next_y < 0 || next_y >= W) continue;
        if (S[next_x][next_y] == '#') ++cnt;
      }
      ans[i].push_back(cnt + '0');
    }
  }
  for (int i = 0, i_len = (H); i < i_len; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
