#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)1e18;
int main() {
  int H, W;
  cin >> H >> W;
  char s[50][50];
  for (int i = (0); i < (H); ++i)
    for (int j = (0); j < (W); ++j) cin >> s[i][j];
  int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
  int dy[] = {0, 1, -1, 1, -1, 0, -1, 1};
  int c[50][50];
  for (int i = (0); i < (H); ++i)
    for (int j = (0); j < (W); ++j) c[i][j] = 0;
  for (int i = (0); i < (H); ++i)
    for (int j = (0); j < (W); ++j) {
      if (s[i][j] == '#') continue;
      for (int k = (0); k < (8); ++k) {
        int ii = i + dx[k];
        int jj = j + dy[k];
        if (ii < 0 || ii > H) continue;
        if (jj < 0 || jj > W) continue;
        if (s[ii][jj] == '#') c[i][j]++;
      }
    }
  for (int i = (0); i < (H); ++i) {
    for (int j = (0); j < (W); ++j) {
      if (s[i][j] == '#') {
        cout << '#';
      } else {
        cout << c[i][j];
      }
    }
    cout << endl;
  }
}
