#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  char tab[a + 5][b + 5];
  for (int i = 0; i < a + 5; i++) {
    for (int j = 0; j < b + 5; j++) tab[i][j] = '+';
  }
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= b; j++) {
      cin >> tab[i][j];
    }
  }
  int tab2[a][b];
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= b; j++) {
      if (tab[i][j] == '.') {
        int tot = 0;
        if (tab[i][j - 1] == '#') tot++;
        if (tab[i - 1][j - 1] == '#') tot++;
        if (tab[i - 1][j] == '#') tot++;
        if (tab[i - 1][j + 1] == '#') tot++;
        if (tab[i][j + 1] == '#') tot++;
        if (tab[i + 1][j + 1] == '#') tot++;
        if (tab[i + 1][j - 1] == '#') tot++;
        if (tab[i + 1][j] == '#') tot++;
        tab2[i][j] = tot;
      }
    }
  }
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= b; j++) {
      if (tab[i][j] == '#')
        cout << '#';
      else
        cout << tab2[i][j];
    }
    cout << endl;
  }
}
