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