#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, nx, ny;
  string s[50];
  int dx[8] = {-1, -1, 0, 0, 1, 1, 0, 0};
  int dy[8] = {0, 0, 1, 1, 0, 0, -1, -1};
  cin >> h >> w;
  for (size_t i = 0; i < h; i++) {
    cin >> s[i];
  }
  int ans;
  for (size_t i = 0; i < w; i++) {
    for (size_t j = 0; j < h; j++) {
      ans = 0;
      for (size_t k = 0; k < 8; k++) {
        nx = j + dx[k];
        ny = i + dy[k];
        if (0 <= nx && ny <= w - 1 && 0 <= nx && ny <= h - 1) {
          if (s[nx][ny] == '#') ans++;
        }
        s[nx][ny] = ans + '0';
      }
      cout << s[i][j];
    }
    cout << endl;
  }
}
