#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, c = 0;
  cin >> n >> m;
  char a[50][50];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      c = 0;
      if (a[i][j] == '#') {
        cout << '#';
        if (j == m - 1) {
          cout << endl;
        }
        continue;
      }
      c += (a[i - 1][j - 1] == '#');
      c += (a[i][j - 1] == '#');
      c += (a[i + 1][j - 1] == '#');
      c += (a[i - 1][j] == '#');
      c += (a[i + 1][j] == '#');
      c += (a[i + 1][j + 1] == '#');
      c += (a[i][j + 1] == '#');
      c += (a[i - 1][j + 1] == '#');
      cout << c;
      if (j == m - 1) {
        cout << endl;
      }
    }
  }
}
