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