#include <bits/stdc++.h>
using namespace std;
int main() {
  int row, column, num;
  string s_row[50], out[50];
  cin >> row >> column;
  for (int i = 0; i < row; i++) cin >> s_row[i];
  for (int i = 0; i < row; i++) {
    for (int l = 0; l < column; l++) {
      if (s_row[i].at(l) == '#') {
        out[i].at(l) == '#';
        continue;
      }
      num = 48;
      for (int j = -1; j <= 1; j++) {
        for (int k = -1; k <= 1; k++) {
          if (j != 0 || k != 0) {
            int r = i + j, c = l + k;
            if (r < 0 || r >= row || c < 0 || c >= column) continue;
            if (s_row[r].at(c) == '#') num++;
          }
        }
      }
      out[i].at(l) = num;
    }
  }
  for (int i = 0; i < row; i++) cout << out[i] << endl;
}
