#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int maxn = (int)-1;
const double eps = 1e-6;
bool eq(const double &a, double const &b) { return fabs(a - b) < eps; }
bool ls(const double &a, double const &b) { return a + eps < b; }
bool le(const double &a, double const &b) { return eq(a, b) || ls(a, b); }
char s[55][55];
int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  for (int i = (0); i < (h); ++i) {
    scanf("%s", s[i]);
  }
  for (int i = (0); i < (h); ++i) {
    for (int j = (0); j < (w); ++j) {
      if (s[i][j] == '#') continue;
      int cnt = 0;
      for (int k = (0); k < (3); ++k)
        for (int l = (0); l < (3); ++l) {
          int x = i + k - 1, y = j + l - 1;
          if (x != y && x >= 0 && x < h && y >= 0 && y < w) {
            if (s[x][y] == '#') cnt++;
          }
        }
      s[i][j] = '0' + cnt;
    }
  }
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j) {
      printf("%c", s[i][j]);
      if (j == w - 1) printf("\n");
    }
  return 0;
}
