#include <bits/stdc++.h>
int main(int argc, char const* argv[]) {
  int h, w;
  std::cin >> h >> w;
  auto vec = std::vector<std::string>(h);
  for (auto& s : vec) {
    std::cin >> s;
  }
  auto result = std::vector<std::vector<int>>(h, std::vector<int>(w, 0));
  for (int i = 0; i < h; ++i) {
    auto str = vec[i];
    for (int j = 0; j < w; ++j) {
      auto c = str[j];
      if (c == '#') {
        bool top = i == 0;
        bool bottom = i == (h - 1);
        bool left = j == 0;
        bool right = j == (w - 1);
        result[i][j] = -99;
        if (top && !left && !right) {
          result[i][j - 1]++;
          result[i][j + 1]++;
          result[i + 1][j - 1]++;
          result[i + 1][j]++;
          result[i + 1][j + 1]++;
        }
        if (top && left) {
          result[i][j + 1]++;
          result[i + 1][j]++;
          result[i + 1][j + 1]++;
        }
        if (top && right) {
          result[i][j - 1]++;
          result[i + 1][j - 1]++;
          result[i + 1][j]++;
        }
        if (left && !top && !bottom) {
          result[i - 1][j]++;
          result[i - 1][j + 1]++;
          result[i][j + 1]++;
          result[i + 1][j]++;
          result[i + 1][j + 1]++;
        }
        if (left && bottom) {
          result[i - 1][j]++;
          result[i - 1][j + 1]++;
          result[i][j + 1]++;
        }
        if (right && !top && !bottom) {
          result[i - 1][j - 1]++;
          result[i - 1][j]++;
          result[i][j - 1]++;
          result[i + 1][j - 1]++;
          result[i + 1][j]++;
        }
        if (bottom && right) {
          result[i - 1][j - 1]++;
          result[i - 1][j]++;
          result[i - 1][j + 1]++;
          result[i][j - 1]++;
          result[i][j + 1]++;
        }
        if (bottom && !left && !right) {
          result[i - 1][j - 1]++;
          result[i - 1][j]++;
          result[i - 1][j + 1]++;
          result[i][j - 1]++;
          result[i][j + 1]++;
        }
        if (!top && !left && !bottom && !right) {
          result[i - 1][j - 1]++;
          result[i - 1][j]++;
          result[i - 1][j + 1]++;
          result[i][j - 1]++;
          result[i][j + 1]++;
          result[i + 1][j - 1]++;
          result[i + 1][j]++;
          result[i + 1][j + 1]++;
        }
      }
    }
  }
  for (auto hv : result) {
    for (auto w : hv) {
      if (w < 0) {
        std::cout << '#';
      } else {
        std::cout << w;
      }
    }
    std::cout << std::endl;
  }
}
