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