#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H + 2);
  vector<vector<int>> memo;
  int s;
  for (int i = 1; i <= H; i++) {
    S[i].push_back('.');
    for (int j = 1; j <= W; j++) {
      cin >> s;
      S[i].push_back(s);
      if (s == '.') {
        memo.push_back({i, j});
      }
    }
    S[i].push_back('.');
  }
  int tmp;
  for (int i = 0; i < memo.size(); i++) {
    for (int j = -1; j <= 1; j++) {
      for (int k = -1; k <= 1; k++) {
        if (S[memo[i][0] + j][memo[i][1] + k] == '#') {
          tmp++;
        }
      }
    }
    S[memo[i][0]][memo[i][1]] = char(tmp);
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cout << S[i][j] << endl;
    }
  }
}
