#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> areas = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1},
                             {1, 1},   {1, 0},  {1, -1}, {0, -1}};
int countMines(vector<vector<char>> G, int i, int j) {
  int n = 0;
  for (auto& area : areas) {
    int ii = i + area[0], jj = j + area[1];
    if (ii < 0 || jj < 0)
      continue;
    else if (ii >= G.size() || jj >= G[0].size())
      continue;
    if (G[ii][jj] == '#') n++;
  }
  return n;
}
int main() {
  int H, W;
  string s;
  vector<vector<char>> G;
  for (int i = 0; i < H; ++i) {
    cin >> s;
    for (int j = 0; j < W; ++j) {
      G[i][j] = s[j];
    }
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (G[i][j] == '.')
        cout << countMines(G, i, j);
      else
        cout << '#';
    }
    cout << '\n';
  }
  cout << endl;
  return 0;
}
