#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <typename T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
int H, W;
string maze[500];
string ans[500];
bool cnd(int y, int x) {
  return y >= 0 && x >= 0 && y < H && x < W && maze[y][x] == '#';
}
int cntf(int x, int y) {
  int cnt = 0;
  if (cnd(y - 1, x)) cnt++;
  if (cnd(y + 1, x)) cnt++;
  if (cnd(y, x - 1)) cnt++;
  if (cnd(y, x + 1)) cnt++;
  if (cnd(y - 1, x - 1)) cnt++;
  if (cnd(y + 1, x - 1)) cnt++;
  if (cnd(y - 1, x + 1)) cnt++;
  if (cnd(y + 1, x + 1)) cnt++;
  return cnt;
}
int main() {
  cin >> H >> W;
  for (int y = 0; y < (int)(H); y++) {
    cin >> maze[y];
  }
  for (int y = 0; y < (int)(H); y++) {
    for (int x = 0; x < (int)(W); x++) {
      if (maze[y][x] != '#')
        ans[y][x] = cntf(x, y) + '0';
      else
        ans[y][x] = '#';
    }
  }
  for (int y = 0; y < (int)(H); y++) {
    for (int x = 0; x < (int)(W); x++) {
      cout << ans[y][x];
    }
    cout << endl;
  }
}
