#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
char map[maxn][maxn];
int a[maxn][maxn] = {0};
int dir[8][2] = {-1, 0, -1, -1, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1};
int cnt(int x, int y) {
  int ans = 0;
  for (int i = 0; i < 8; i++) {
    int fx = x + dir[i][0];
    int fy = y + dir[i][1];
    if (fx < 0 || fy < 0) continue;
    if (map[fx][fy] == '#') ans++;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) scanf("%s", map[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      a[i][j] = cnt(i, j);
      if (map[i][j] == '.')
        cout << a[i][j];
      else
        cout << map[i][j];
    }
    cout << endl;
  }
}
