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