#include <bits/stdc++.h>
using namespace std;
const int INF = 10000000;
const long long INFL = (1LL << 40);
const int MOD = pow(10, 9) + 7;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  }
  return os;
}
template <typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge& operator=(const int& x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
double dist(double a, double b, double c, double d) {
  return sqrt((a - c) * (a - c) + (b - d) * (b - d));
}
bool check(int x, int y, vector<string> a, vector<string> b) {
  for (auto i = 0; i < b.size(); i++) {
    for (auto j = 0; j < b.size(); j++) {
      if (a[x + i][y + j] != b[i][j]) return false;
    }
  }
  return true;
}
int dist(pair<int, int> a, pair<int, int> b) {
  return abs(a.first - b.first) + abs(a.second - b.second);
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h + 2);
  string edge;
  for (auto i = 0; i < w + 2; i++) edge += ".";
  s[0] = edge;
  for (int i = 0; i < h; i++) {
    string temp;
    temp += ".";
    string temp2;
    cin >> temp2;
    temp += temp2;
    temp += ".";
    s[i + 1] = temp;
  }
  s[h + 1] = edge;
  vector<vector<char>> out(h);
  for (int i = 0; i < h; i++) out[i].resize(w);
  for (auto i = 1; i < h + 1; i++) {
    for (auto j = 1; j < w + 1; j++) {
      if (s[i][j] == '#') {
        out[i - 1][j - 1] = '#';
        continue;
      };
      int count = 0;
      count += (s[i + 1][j] == '#');
      count += (s[i - 1][j] == '#');
      count += (s[i][j + 1] == '#');
      count += (s[i][j - 1] == '#');
      count += (s[i + 1][j + 1] == '#');
      count += (s[i + 1][j - 1] == '#');
      count += (s[i - 1][j + 1] == '#');
      count += (s[i - 1][j - 1] == '#');
      out[i - 1][j - 1] = count + '0';
    }
  }
  for (int i = 0; i < h; i++) cout << out[i] << endl;
  return 0;
}
