#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> board(h);
  for (int y = 0; y < h; y++) {
    string s;
    cin >> s;
    board[y] = s;
  }
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (board[y][x] == '#') {
        continue;
      }
      int cnt = 0;
      for (int i = 0; i < 8; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx < 0 || w <= nx && ny < 0 && h <= ny) {
          continue;
        }
        if (board[ny][nx] == '#') {
          cnt++;
        }
      }
      board[y][x] = (char)cnt;
    }
  }
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      cout << board[y][x];
    }
    cout << "\n";
  }
  return 0;
}
