#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '.') {
        s[i][j] = '0';
      } else {
        s[i][j] = '#';
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        cout << "#";
      } else {
        int count = 0;
        if (s[i - 1][j - 1] == '#') {
          count++;
        }
        if (s[i - 1][j] == '#') {
          count++;
        }
        if (s[i - 1][j + 1] == '#') {
          count++;
        }
        if (s[i][j - 1] == '#') {
          count++;
        }
        if (s[i][j + 1] == '#') {
          count++;
        }
        if (s[i + 1][j - 1] == '#') {
          count++;
        }
        if (s[i + 1][j] == '#') {
          count++;
        }
        if (s[i + 1][j + 1] == '#') {
          count++;
        }
        cout << count;
      }
    }
    cout << "\n";
  }
  return 0;
}
