#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int cnt = 0;
      if (s[i][j] == '.') {
        if (s[i - 1][j] == '#') {
          cnt++;
        }
        if (s[i + 1][j] == '#') {
          cnt++;
        }
        if (s[i][j - 1] == '#') {
          cnt++;
        }
        if (s[i][j + 1] == '#') {
          cnt++;
        }
        if (s[i - 1][j - 1] == '#') {
          cnt++;
        }
        if (s[i - 1][j + 1] == '#') {
          cnt++;
        }
        if (s[i + 1][j + 1] == '#') {
          cnt++;
        }
        if (s[i + 1][j - 1] == '#') {
          cnt++;
        }
        s[i][j] = cnt + '0';
      }
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cout << s[i][j];
      if (j == w - 1) {
        cout << endl;
      }
    }
  }
  return 0;
}
