#include <bits/stdc++.h>
using namespace std;
string S[55];
int h, w;
int main() {
  int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
  int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  cin >> h >> w;
  char ans[55][55];
  for (int i = 1; i <= h; i++) cin >> S[i];
  for (int i = 1; i <= h; i++) S[i] = ' ' + S[i];
  for (int i = 0; i <= w; i++) S[0][i] = ' ';
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (S[i][j] == '#')
        ans[i - 1][j - 1] = '#';
      else {
        int cnt = 0;
        for (int x = 0; x < 8; x++) {
          if (i + dy[x] >= h || i + dy[x] < 0 || j + dx[x] >= w ||
              j + dx[x] < 0)
            continue;
          if (S[i + dy[x]][j + dx[x]] == '#') cnt++;
        }
        ans[i - 1][j - 1] = '0' + cnt;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}
