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