#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
int n, m, h, w;
string s[60] = {};
int cnt[60][60] = {};
int a[60] = {}, b[60] = {};
int map[60][60] = {};
int main() {
  for (int i = 0; i < 60; i++) {
    for (int j = 0; j < 60; j++) {
      cnt[i][j] = 0;
    }
  }
  cin >> h >> w;
  for (int i = 1; i < h + 1; i++)
    for (int j = 1; j < w + 1; j++) cin >> s[i][j];
  for (int i = 1; i < h + 1; i++) {
    for (int j = 1; j < w + 1; j++) {
      for (int k = -1; k <= 1; k++) {
        for (int l = -1; l <= 1; l++) {
          if (s[i + k][j + l] == '#') {
            cnt[i][j]++;
          }
        }
      }
    }
  }
  for (int i = 1; i < h + 1; i++) {
    for (int j = 1; j < w + 1; j++) {
      if (s[i][j] == '#') {
        cout << s[i][j];
      } else {
        cout << cnt[i][j];
      }
    }
    cout << endl;
  }
}
