#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int H, W;
  cin >> H >> W;
  string s[50];
  int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
  int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  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 count = 0;
      if (s[i][j] == '#') {
        cout << '#';
        continue;
      }
      for (int k = 0; k < 8; k++) {
        if (i + dy[k] < 0 || i + dy[k] >= H) {
          continue;
        } else if (j + dx[k] < 0 || j + dx[k] >= W) {
          continue;
        } else if (s[i + dy[k]][j + dx[k]] == '#') {
          count++;
        }
      }
      cout << count;
    }
    cout << endl;
  }
}
