#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, d = 0;
  cin >> a >> b;
  char c[a][b];
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      d = 0;
      for (int k = 0; k < 3; k++) {
        for (int l = 0; l < 3; l++) {
          if (c[i - 1 + k][j - 1 + l] == '#') d++;
        }
      }
      if (c[i][j] == '#')
        cout << '#';
      else
        cout << d;
    }
    cout << endl;
  }
}
