#include <bits/stdc++.h>
using namespace std;

int main() {
  int H, W, a = 0, b, c, d;
  cin >> H >> W;
  string S, e;
  for (; S.size() < H * W; S += e) cin >> e;
  for (; a < H * W; a++) {
    if (a && !(a % W)) cout << endl;
    if (S.at(a) == '.') {
      for (b = 0, c = a / W; c < a / W + 3; c++) for (d = a % W; d < a % W + 3; d++) if (c * d && c < H + 1 && d < W + 1) if (S.at(W * c - W + d - 1) == '#') b++;
      cout << b;
    }
    else cout << '#';
  }
}