#include <bits/stdc++.h>
using namespace std;
int H, W;
bool isOK(int i, int j) {
  return (0 <= i and i <= H - 1 and 0 <= j and j <= W - 1);
}
int main() {
  int H, W;
  cin >> H >> W;
  string S[H];
  for (int i = 0; i < H; i++) cin >> S[i];
  int cnt;
  for (int l = 0; l < H; l++) {
    for (int k = 0; k < W; k++) {
    }
  }
  for (int l = 0; l < H; l++) {
    for (int k = 0; k < W; k++) {
      cnt = 0;
      if (S[l][k] == '.') {
        for (int i = -1; i <= 1; i++) {
          for (int j = -1; j <= 1; j++) {
            if ((not(i == 0 and j == 0)) and isOK(l + j, k + i) and
                S[l + j][k + i] == '#')
              cnt++;
          }
        }
        cout << cnt;
      } else {
        cout << "#";
      }
    }
    cout << endl;
  }
}
