#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int rows, cols;
  cin >> rows >> cols;
  char grid[50][50];
  for (int r = 0; r < rows; r++)
    for (int c = 0; c < cols; c++) cin >> grid[r][c];
  for (int r = 0; r < rows; r++)
    for (int c = 0; c < cols; c++)
      if (grid[r][c] == '.') {
        int bombs = 0;
        for (int dr = -1; dr <= 1; dr++)
          for (int dc = -1; dc <= 1; dc++) {
            int r0 = r + dr;
            int c0 = c + dc;
            bool good_r = r0 >= 0 && r0 < rows;
            bool good_c = c0 >= 0 && c0 < cols;
            if (good_r && good_c) bombs += grid[r0][c0] == '#';
          }
        grid[r][c] = bombs + '0';
      }
  for (int r = 0; r < rows; r++) {
    for (int c = 0; c < cols; c++) cout << grid[r][c];
    cout << '\n';
  }
}
