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