#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void solve() {
  int h, w;
  cin >> h >> w;
  char m[h + 2][w + 2];
  for (int i = 1; i <= h; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= w; j++) {
      m[i][j] = s[j - 1];
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (m[i][j] == '#') continue;
      int bomb = 0;
      for (int t = -1; t <= 1; t++) {
        for (int s = -1; s <= 1; s++) {
          if (m[i + t][j + s] == '#') bomb++;
        }
      }
      m[i][j] = char(bomb + '0');
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cout << m[i][j];
    }
    cout << "\n";
  }
}
int main() {
  solve();
  return 0;
}
