#include <bits/stdc++.h>
using namespace std;
int main() {
  int x[8] = {1, 1, 1, 0, 0, -1, -1, -1};
  int y[8] = {1, 0, -1, 1, -1, 1, 0, -1};
  int H, W;
  cin >> H >> W;
  char S[50][50];
  int A[50][50];
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        int count = 0;
        for (int k = 0; k < 8; k++) {
          if ((i + y[k] >= 0 || i + y[k] < H) &&
              (j + x[k] >= 0 || j + x[k] < W)) {
            if (S[i + y[k]][j + x[k]] == '#') {
              count++;
            }
          }
        }
        A[i][j] = count;
      } else {
        A[i][j] = '#';
      }
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A[i][j] != 35) {
        cout << A[i][j];
      } else {
        cout << '#';
      }
    }
    cout << endl;
  }
  return 0;
}
