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