#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
int main() {
  int h, w;
  cin >> h >> w;
  string bomb[50];
  for (int i = 0; i < (h); ++i) {
    cin >> bomb[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 (bomb[i][j] == '#') continue;
      int num = 0;
      for (int d = 0; d < 8; d++) {
        const int ni = i + dy[d];
        const int nj = j + dx[d];
        if (ni < 0 && h <= ni) continue;
        if (nj <= w && w <= nj) continue;
        if (bomb[ni][nj] == '#') num++;
      }
      bomb[i][j] = char(num + '0');
    }
  }
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      cout << bomb[i][j];
    }
    cout << endl;
  }
  return 0;
}
