#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const long long llnrm = LLONG_MAX;
const int nrm = INT_MAX;
const int nrn = INT_MIN;
const int nmax = 1e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int ans, r, l, tmp, nrd;
char c[50][50];
int a[100][100];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> r >> l;
  for (int i = 0; i < r; i++)
    for (int j = 0; j < l; j++) {
      cin >> c[i][j];
      a[i][j] = 0;
    }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < l; j++) {
      if (c[i][j] == '#') {
        if (c[i][j + 1] != '#') a[i][j + 1]++;
        if (c[i][j - 1] != '#') a[i][j - 1]++;
        if (c[i - 1][j] != '#') a[i - 1][j]++;
        if (c[i - 1][j - 1] != '#') a[i - 1][j - 1]++;
        if (c[i - 1][j + 1] != '#') a[i - 1][j + 1]++;
        if (c[i + 1][j] != '#') a[i + 1][j]++;
        if (c[i + 1][j - 1] != '#') a[i + 1][j - 1]++;
        if (c[i + 1][j + 1] != '#') a[i + 1][j + 1]++;
      }
    }
  }
  for (int i = 0; i < r; i++)
    for (int j = 0; j < l; j++) {
      if (c[i][j] == '#')
        cout << '#';
      else
        cout << a[i][j];
      if (j == l - 1) cout << endl;
    }
  return 0;
}
