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