#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
int H, W;
vector<string> graph;
int pjt[60][60];
queue<pair<int, int> > q;
const int dy[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int main() {
  cin >> H >> W;
  graph.resize(H);
  for (int i = 0; i < W; i++) {
    cin >> graph[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (graph[i][j] == '#') {
        q.push(make_pair(i, j));
        pjt[i][j] = -1;
      }
    }
  }
  while (!q.empty()) {
    int y, x;
    pair<int, int> qf = q.front();
    q.pop();
    tie(y, x) = qf;
    for (int dir = 0; dir < 8; dir++) {
      int ny = y + dy[dir];
      int nx = x + dx[dir];
      if (0 <= ny && ny < H && 0 <= nx && nx < W && graph[ny][nx] == '.')
        pjt[ny][nx]++;
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (pjt[i][j] == -1) {
        cout << '#';
        if (j == W - 1) cout << endl;
        continue;
      }
      cout << pjt[i][j];
      if (j == W - 1) cout << endl;
    }
  }
}
