#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int H, W;
  cin >> H >> W;
  char str[H][W];
  int check[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> str[i][j];
      check[i][j] = 0;
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (str[i][j] == '#') {
        check[i][j] = '#';
        if (str[i - 1][j - 1] == '.') check[i - 1][j - 1]++;
        if (str[i - 1][j] == '.') check[i - 1][j]++;
        if (str[i - 1][j + 1] == '.') check[i - 1][j + 1]++;
        if (str[i][j - 1] == '.') check[i][j - 1]++;
        if (str[i][j + 1] == '.') check[i][j + 1]++;
        if (str[i + 1][j - 1] == '.') check[i + 1][j - 1]++;
        if (str[i + 1][j] == '.') check[i + 1][j]++;
        if (str[i + 1][j + 1] == '.') check[i + 1][j + 1]++;
      }
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (check[i][j] != '#' &&
          ((j == 0 || j == W - 1) && (i != 0 && i != H - 1)))
        cout << check[i][j] - 2;
      else if (check[i][j] != '#' && ((j == 0 || j == W - 1) && i == 0))
        cout << check[i][j] - 3;
      else if (check[i][j] != '#' && ((j == 0 || j == W - 1) && i == H - 1))
        cout << check[i][j] - 1;
      else if (check[i][j] != '#')
        cout << check[i][j];
      else
        cout << '#';
    }
    cout << endl;
  }
  return 0;
}
