#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T Max(T a, T b) {
  return a > b ? a : b;
}
template <typename T>
inline T Min(T a, T b) {
  return a < b ? a : b;
}
template <typename T>
inline T Abs(T a) {
  return a < 0 ? -a : a;
}
template <typename T>
inline void read(T &a) {
  a = 0;
  T k = 1;
  char c = getc(stdin);
  while (c < '0' || c > '9') k = c == '-' ? -1 : k, c = getc(stdin);
  while (c >= '0' && c <= '9') a = a * 10 + (c ^ 48), c = getc(stdin);
  if (c != '.') {
    a *= k;
    return;
  }
  T t = 0.1;
  while (c < '0' || c > '9') c = getc(stdin);
  while (c >= '0' && c <= '9') a += t * (c ^ 48), c = getc(stdin), t *= 0.1;
  a *= k;
}
template <typename T>
void write(T a, char t = ' ') {
  if (a == 0) {
    putc(48, stdout), putc(t, stdout);
    return;
  }
  if (a < 0) {
    a = -a;
    putc('-', stdout);
  }
  char c[30];
  int le = 0;
  while (a) {
    c[++le] = a % 10 + 48;
    a /= 10;
  }
  for (register int i = le; i >= 1; --i) putc(c[i], stdout);
  putc(t, stdout);
}
char s[100][100], a[100][100];
int n, m, dx[10] = {0, 0, 1, 1, 1, -1, -1, -1},
          dy[10] = {1, -1, -1, 0, 1, -1, 0, 1};
int main() {
  ios::sync_with_stdio(false);
  read(n), read(m);
  for (register int i = 1; i <= n; ++i) cin >> s[i];
  for (register int i = 1; i <= n; ++i) {
    for (register int j = 0; j < m; ++j) {
      if (s[i][j] == '#')
        a[i][j] = '#';
      else {
        a[i][j] = '0';
        for (int k = 0; k < 8; ++k)
          if (s[i + dx[k]][j + dy[k]] == '#') ++a[i][j];
      }
      putc(a[i][j], stdout);
    }
    putc('\n', stdout);
  }
}
