#include <bits/stdc++.h>
using namespace std;
pair<int, int> d[]{{-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}};
int main()
  {int H, W; cin >> H >> W;
  string S[H]; for (auto &s: S) cin >> s;
  for (int i{}; i < H; ++i)
    {for (int j{}; j < W; ++j)
      {if (S[i][j] == '#') {cout << "#"; continue;}
      int c{}; for (auto [a, b] : d) {int y{i + a}, x{j + b}; c += 0 <= y and y < H and 0 <= x and x < W and S[y][x] == '#';}
      cout << c;}
    puts("");}}