#include <bits/stdc++.h>
using namespace std;
int asc(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int desc(const void *a, const void *b) { return *(int *)b - *(int *)a; }
int main() {
  int h, w, count = 0;
  cin >> h >> w;
  char s[h + 1][w + 1];
  for (int(i) = 0; (i) < (h + 2); ++(i)) {
    for (int(j) = 0; (j) < (w + 2); ++(j)) {
      if (i == 0 || i == h + 1 || j == 0 || j == w + 1) {
        s[i][j] = '.';
      } else {
        cin >> s[i][j];
      }
    }
  }
  for (int(i) = 0; (i) < (h); ++(i)) {
    for (int(j) = 0; (j) < (w); ++(j)) {
      if (s[i + 1][j + 1] == '.') {
        count = 0;
        for (int(r) = 0; (r) < (3); ++(r)) {
          for (int(k) = 0; (k) < (3); ++(k)) {
            if (s[i + r][j + k] == '#') {
              ++count;
            }
          }
        }
        cout << count;
      } else {
        cout << "#";
      }
    }
    cout << endl;
  }
  return 0;
}
