#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main(void) {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (long long i = (long long)0; i < (long long)h; i++) {
    cin >> s[i];
  };
  vector<string> ans(h);
  for (long long i = (long long)0; i < (long long)h; i++) {
    for (long long j = (long long)0; j < (long long)w; j++) {
      if (s[i][j] == '#') {
        ans[i].push_back('#');
        continue;
      }
      int tmp = 0;
      if (i != 0) {
        if (j != 0) tmp += s[i - 1][j - 1] == '#';
        tmp += s[i - 1][j] == '#';
        if (j != w - 1) tmp += s[i - 1][j + 1] == '#';
      }
      if (j != 0) tmp += s[i][j - 1] == '#';
      if (j != w - 1) tmp += s[i - 1][j + 1] == '#';
      if (i != h - 1) {
        if (j != 0) tmp += s[i + 1][j - 1] == '#';
        tmp += s[i + 1][j] == '#';
        if (j != w - 1) tmp += s[i + 1][j + 1] == '#';
      }
      char x = '0' + tmp;
      ans[i].push_back(x);
    }
  }
  for (long long i = (long long)0; i < (long long)h; i++) {
    cout << (ans[i]) << "\n";
  }
}
