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