#include <bits/stdc++.h>
using ll = long long;
using namespace std;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') continue;
      int cnt = 0;
      for (int k = 0; k < 8; k++) {
        int y = i + dy[k];
        int x = j + dx[k];
        if (y < 0 || H <= y) continue;
        if (x < 0 || W <= x) continue;
        if (S[y][x] == '#') cnt++;
      }
      S[i][j] = '0' + cnt;
    }
  }
  for (int i = 0; i < W; i++) std::cout << S[i] << '\n';
  return 0;
}
