#include <bits/stdc++.h>
using namespace std;
int Nx[10] = {0, 0, -1, 1, -1, 1, -1, 1};
int Ny[10] = {1, -1, 0, 0, -1, 1, 1, -1};
int main() {
  int n, m;
  cin >> n >> m;
  char ch[n + 2][m + 2];
  for (int i = 0; i <= n + 1; i++)
    for (int j = 0; j <= n + 1; j++) ch[i][j] = '0';
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> ch[i][j];
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (ch[i][j] == '#')
        cout << "#";
      else {
        for (int k = 0; k <= 7; k++)
          if (ch[i + Nx[k]][j + Ny[k]] == '#') ans++;
        cout << ans;
        ans = 0;
      }
    cout << endl;
  }
  return 0;
}
