#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ddx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int ddy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
int main() {
  long long int A, B, C, D, E, F, N, M, K, L, R, X, Y, H, W, sum = 0, num = 0,
                                                             flag = 0;
  string S, T;
  cin >> H >> W;
  vector<vector<char>> G(H, vector<char>(W, '.'));
  vector<vector<char>> P(H, vector<char>(W, '.'));
  for (long long int i = 0; i < H; i++)
    for (long long int j = 0; j < W; j++) cin >> G[i][j];
  for (long long int i = 0; i < H; i++)
    for (long long int j = 0; j < W; j++) {
      sum = 0;
      if (G[i][j] != '#') {
        for (long long int k = 0; k < 8; k++) {
          auto nx = i + ddx[k];
          auto ny = j + ddy[k];
          if (nx > H - 1 || ny > W - 1 || nx < 0 || ny < 0) continue;
          if (G[nx][ny] == '#') sum++;
        }
        P[i][j] = (char)'0' + sum;
      } else
        P[i][j] = '#';
    }
  for (long long int i = 0; i < H; i++)
    for (long long int j = 0; j < W; j++) {
      if (j + 1 == W)
        cout << P[i][j] << endl;
      else
        cout << P[i][j] << " ";
    }
}
