#include <bits/stdc++.h>
using namespace std;
template <typename T>
void view(T e) {
  std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T>& v) {
  for (const auto& e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>>& vv) {
  for (const auto& v : vv) {
    view(v);
  }
}
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int MOD = 1000000007;
const int INF = 1e9;
const int mod = 1000000007;
const int inf = 1e9;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1};
int main() {
  int r, c;
  cin >> r >> c;
  vector<vector<char>> grid(r, vector<char>(c));
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++) cin >> grid[i][j];
  vector<vector<int>> ans(r, vector<int>(c, 0));
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < r; j++) {
      if (grid[i][j] == '.') {
        int cnt = 0;
        for (int k = 0; k < 8; k++) {
          int x = i + ddx[k];
          int y = j + ddy[k];
          if (x >= 0 && x < r && y >= 0 && y < c && grid[x][y] == '#') cnt++;
        }
        ans[i][j] = cnt;
      }
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      if (grid[i][j] == '#') {
        cout << '#';
      } else {
        cout << ans[i][j];
      }
    }
    cout << endl;
  }
}
