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