#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, sum = 0, j;
  char a[50][50];
  while (cin >> H >> W) {
    for (int i = 1; i <= H; i++)
      for (int j = 1; j <= W; j++) cin >> a[i][j];
    for (int i = 1; i <= H; i++)
      for (int j = 1; j <= W; j++) {
        if (a[i][j] == '#')
          cout << a[i][j];
        else {
          if (a[i - 1][j - 1] == '#') sum++;
          if (a[i - 1][j] == '#') sum++;
          if (a[i - 1][j + 1] == '#') sum++;
          if (a[i + 1][j] == '#') sum++;
          if (a[i + 1][j - 1] == '#') sum++;
          if (a[i + 1][j + 1] == '#') sum++;
          if (a[i][j - 1] == '#') sum++;
          if (a[i][j + 1] == '#') sum++;
          cout << sum;
        }
        sum = 0;
        if (j == W) cout << endl;
      }
    cout << endl;
  }
  return 0;
}
