#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  char S[50][50];
  char ans[50][50];
  int baku[50][50];
  for (int i = 0; i < (H); ++i) {
    for (int j = 0; j < (W); ++j) {
      cin >> S[i][j];
      baku[i][j] = 0;
    }
  }
  for (int i = 0; i < (H); ++i) {
    for (int j = 0; j < (W); ++j) {
      if (S[i][j] == '#') {
        ans[i][j] = '#';
        cout << ans[i][j];
        if (H != 0 && j == W - 1) cout << endl;
        continue;
      }
      for (int k = 0; k < (3); ++k) {
        for (int l = 0; l < (3); ++l) {
          if (S[k + i - 1][l + j - 1] == '#') baku[i][j]++;
        }
      }
      ans[i][j] = '0' + baku[i][j];
      cout << ans[i][j];
      if (H != 0 && j == W - 1) cout << endl;
    }
  }
}
