#include <bits/stdc++.h>
using namespace std;
int main() {
  int H;
  int W;
  cin >> H >> W;
  vector<string> vec(H);
  for (int i = 0; i < H; i++) {
    cin >> vec.at(i);
  }
  const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (vec.at(i).at(j) == '#') continue;
      int cnt = 0;
      for (int k = 0; k < 8; k++) {
        int x = i + dx[k];
        int y = j + dy[k];
        if (x < 0 || W <= x) continue;
        if (y < 0 || H <= y) continue;
        if (vec.at(x).at(y) == '#') cnt++;
      }
      vec.at(i).at(j) = (char)cnt;
    }
  }
  for (int i = 0; i < H; i++) cout << vec.at(i) << endl;
  return 0;
}
