#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
const long long mod = 1e9 + 7;
const long long INF = mod * mod;
const long long MAX_N = 200;
int main(void) {
  long long H, W;
  string s[50];
  cin >> (H) >> (W);
  for (long long((i)) = 0; ((i)) < ((H)); ((i))++) cin >> (s[(i)]);
  for (long long(h) = 0; (h) < (H); (h)++) {
    for (long long(w) = 0; (w) < (W); (w)++) {
      if (s[h][w] == '#')
        cout << (s[h][w]);
      else if (h == H - 1 && w == W - 1)
        cout << ((s[h - 1][w] == '#') + (s[h][w - 1] == '#') +
                 (s[h - 1][w - 1] == '#'));
      else if (h == 0 && w == W - 1)
        cout << ((s[h + 1][w] == '#') + (s[h][w - 1] == '#') +
                 (s[h + 1][w - 1] == '#'));
      else if (h == H - 1 && w == 0)
        cout << ((s[h - 1][w] == '#') + (s[h][w + 1] == '#') +
                 (s[h - 1][w + 1] == '#'));
      else if (h == 0 && w == 0)
        cout << ((s[h + 1][w] == '#') + (s[h][w + 1] == '#') +
                 (s[h + 1][w + 1] == '#'));
      else if (h == H - 1)
        cout << ((s[h - 1][w] == '#') + (s[h - 1][w - 1] == '#') +
                 (s[h - 1][w + 1] == '#') + (s[h][w - 1] == '#') +
                 (s[h][w + 1] == '#'));
      else if (w == W - 1)
        cout << ((s[h - 1][w - 1] == '#') + (s[h][w - 1] == '#') +
                 (s[h + 1][w - 1] == '#') + (s[h - 1][w] == '#') +
                 (s[h + 1][w] == '#'));
      else if (w == 0)
        cout << ((s[h - 1][w + 1] == '#') + (s[h][w + 1] == '#') +
                 (s[h + 1][w + 1] == '#') + (s[h - 1][w] == '#') +
                 (s[h + 1][w] == '#'));
      else if (h == 0)
        cout << ((s[h + 1][w] == '#') + (s[h + 1][w - 1] == '#') +
                 (s[h + 1][w + 1] == '#') + (s[h][w - 1] == '#') +
                 (s[h][w + 1] == '#'));
      else
        cout << ((s[h - 1][w] == '#') + (s[h - 1][w - 1] == '#') +
                 (s[h - 1][w + 1] == '#') + (s[h + 1][w - 1] == '#') +
                 (s[h + 1][w + 1] == '#') + (s[h + 1][w] == '#') +
                 (s[h][w - 1] == '#') + (s[h][w + 1] == '#'));
    }
    cout << ("") << endl;
  }
  return 0;
}
