#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int INF = 32 << 1;
int H, W;
int A[51][51];
pair<int, int> dir[] = {{-1, 1}, {0, 1},   {1, 1},  {-1, 0},
                        {1, 0},  {-1, -1}, {0, -1}, {1, -1}};
int main() {
  cin >> H >> W;
  for (int i = 1; i <= H; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= s.size(); j++) {
      if (s[j - 1] == '#') {
        A[i][j] = -INF;
        for (auto& d : dir) {
          A[i + d.first][j + d.second] += 1;
        }
      }
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (A[i][j] >= 0) {
        cout << A[i][j];
      } else {
        cout << '#';
      }
    }
    cout << endl;
  }
  cin >> H;
  return 0;
}
