#include <iostream>
using namespace std;

int main()
{
  int H, W;
  cin >> H >> W;
  
  string board[H];
  for (int i = 0; i < H; ++i)
    cin >> board[i];
  
  const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
  const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
  
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (board[i][j] == '#')
        continue;
      
      int numBomb = 0;
      
      for (int d = 0; d < 8; ++d) {
        int neighbor_i = i + dy;
        int neighbor_j = j + dx;
        
        if (neighbor_i < 0 or neighbor_i >= H) continue;
        if (neighbor_j < 0 or neighbor_j >= W) continue;
        ++numBomb;
      }
      
      board[i][j] = char(numBomb + '0');
    }
  }
  
  for (int i = 0; i < H; ++i)
      cout << board[i];
}
