#include <bits/stdc++.h>
using namespace std;
int main() {
  int w, h;
  cin >> h >> w;
  string s[55][55];
  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 k = 0;
      if (s[i][j] == ".") {
        if (s[i - 1][j - 1] == "#") k++;
        if (s[i][j - 1] == "#") k++;
        if (s[i + 1][j - 1] == "#") k++;
        if (s[i - 1][j] == "#") k++;
        if (s[i + 1][j] == "#") k++;
        if (s[i - 1][j + 1] == "#") k++;
        if (s[i][j + 1] == "#") k++;
        if (s[i + 1][j + 1] == "#") k++;
        s[i][j] = k;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << s[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
