#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  string s[50];
  cin >> h >> w;
  for (int i = 0; i < (h); ++i) cin >> s[i];
  const int x[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  const int y[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      if (s[i][j] == '#') continue;
      int num = 0;
      for (int k = 0; k < (8); ++k) {
        if (j + x[k] < 0 || j + x[k] >= w) continue;
        if (i + y[k] < 0 || i + y[k] >= h) continue;
        if (s[i + y[k]][j + x[k]] == '#') num++;
      }
      s[i][j] == char(num + '0');
    }
  }
  for (int i = 0; i < (h); ++i) cout << s[i] << endl;
}
