#include <bits/stdc++.h>
const int MOD = 1000000007;
using namespace std;
template <class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}
template <class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}
template <class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}
void py(bool isUpper = false) {
  if (isUpper) {
    cout << ("YES") << endl;
  } else {
    cout << ("Yes") << endl;
  }
}
void pn(bool isUpper = false) {
  if (isUpper) {
    cout << ("NO") << endl;
  } else {
    cout << ("No") << endl;
  }
}
int main() {
  const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  int h, w;
  cin >> h >> w;
  char table[50][50];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> table[i][j];
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (table[i][j] == '#') {
        cout << "#";
        continue;
      }
      int count = 0;
      for (int k = 0; k < 8; ++k) {
        int x = i + dx[k];
        int y = j + dy[k];
        if (x < 0 || x > h) continue;
        if (y < 0 || y > w) continue;
        if (table[x][y] == '#') {
          count++;
        }
      }
      cout << count;
    }
    cout << endl;
  }
}
