#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H, W;
  vector<string> v(H);
  for (int i = 0; i < H; i++) {
    cin >> v.at(i);
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (v[i][j] == '.') {
        int cnt = 0;
        for (int h = i - 1; h < i + 2; h++) {
          for (int w = j - 1; w < j + 2; j++) {
            if (w < 0 || h < 0 || h >= H || w >= W) continue;
            if (v[h][w] == '#') cnt++;
          }
        }
        v[i][j] = static_cast<char>(cnt);
      }
    }
  }
  for (int i = 0; i < H; i++) {
    cout << v.at(i) << endl;
  }
}
