#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  char a[H + 2][W + 2];
  for (int i = 0; i < W + 2; i++) {
    a[0][i] = '.';
    a[H + 1][i] = '.';
  }
  for (int i = 0; i < H + 2; i++) {
    a[i + 1][0] = '.';
    a[i + 1][W + 1] = '.';
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[1 + i][1 + j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int count = 0;
      if (a[i][j] == '#') {
        count++;
      }
      if (a[i + 1][j] == '#') {
        count++;
      }
      if (a[i + 2][j] == '#') {
        count++;
      }
      if (a[i][j + 1] == '#') {
        count++;
      }
      if (a[i + 2][j + 1] == '#') {
        count++;
      }
      if (a[i][j + 2] == '#') {
        count++;
      }
      if (a[i + 1][j + 2] == '#') {
        count++;
      }
      if (a[i + 2][j + 2] == '#') {
        count++;
      }
      if (a[i + 1][j + 1] == '.') {
        a[i + 1][j + 1] = int(48 + count);
      }
    }
  }
  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < W + 1; j++) {
      cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}
