#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) cin >> s[i];
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (s[i][j] == '.') {
        int count = 0;
        if (s[i - 1][j - 1] == '#') count += 1;
        if (s[i - 1][j] == '#') count += 1;
        if (s[i - 1][j + 1] == '#') count += 1;
        if (s[i][j - 1] == '#') count += 1;
        if (s[i][j + 1] == '#') count += 1;
        if (s[i + 1][j - 1] == '#') count += 1;
        if (s[i + 1][j] == '#') count += 1;
        if (s[i + 1][j + 1] == '#') count += 1;
        s[i][j] = count;
      }
    }
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cout << s[i][j];
    }
    cout << endl;
  }
}
