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