#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> vec(H);
  for (int i = 0; i < (int)(H); i++) vec[i].reserve((size_t)(W + 10));
  for (int i = 0; i < (int)(H); i++) cin >> vec[i];
  int cnt;
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      if (vec[i][j] == '.') {
        cnt = 0;
        for (int k = i - 1; k <= i + 1; ++k) {
          for (int l = j - 1; l <= j + 1; ++l) {
            if (k < 0 || l < 0) {
              continue;
            } else if (vec[k][l] == '#') {
              cnt++;
            }
          }
        }
        cout << cnt;
      } else {
        cout << '#';
      }
    }
    cout << "\n";
  }
  return 0;
}
