#include <bits/stdc++.h>
int main() {
  int a, b, count;
  std::cin >> a >> b;
  std::string str[50];
  for (int i = 1; i <= a; i++) {
    std::cin >> str[i];
  }
  for (int i = 0; i <= b + 1; i++) {
    str[0][i] = '.';
    str[a + 1][i] = '.';
  }
  for (int i = 1; i <= a; i++) {
    str[i].insert(b, ".");
    str[i].insert(0, ".");
  }
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= b; j++) {
      count = 0;
      if (str[i][j] == '#') {
        std::cout << str[i][j];
        continue;
      } else {
        if (str[i - 1][j - 1] == '#') {
          count++;
        }
        if (str[i - 1][j] == '#') {
          count++;
        }
        if (str[i - 1][j + 1] == '#') {
          count++;
        }
        if (str[i][j - 1] == '#') {
          count++;
        }
        if (str[i][j + 1] == '#') {
          count++;
        }
        if (str[i + 1][j - 1] == '#') {
          count++;
        }
        if (str[i + 1][j] == '#') {
          count++;
        }
        if (str[i + 1][j + 1] == '#') {
          count++;
        }
      }
      std::cout << count;
    }
    std::cout << std::endl;
  }
  return 0;
}
