#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const long long INF = 1LL << 60;
using vll = vector<long long>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pair<long long, long long> = pair<long long, long long>;
int main() {
  long long h, w;
  cin >> h >> w;
  vstr s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector<vector<char>> ans(h, vector<char>(w));
  for (long long i = 0; i < (h); i++)
    for (long long j = 0; j < (w); j++) {
      if (s[i][j] == '#')
        ans[i][j] = '#';
      else {
        long long k = 0;
        if (i - 1 >= 0 && j - 1 >= 0) {
          if (s[i - 1][j - 1] == '#') k++;
        }
        if (i - 1 >= 0) {
          if (s[i - 1][j] == '#') k++;
        }
        if (i - 1 >= 0 && j + 1 < w) {
          if (s[i - 1][j + 1] == '#') k++;
        }
        if (j - 1 >= 0) {
          if (s[i][j - 1] == '#') k++;
        }
        if (j + 1 < w) {
          if (s[i][j + 1] == '#') k++;
        }
        if (i + 1 < h && j - 1 >= 0) {
          if (s[i + 1][j - 1] == '#') k++;
        }
        if (i + 1 < h) {
          if (s[i + 1][j] == '#') k++;
        }
        if (i + 1 < w && j + 1 < h) {
          if (s[i + 1][j + 1] == '#') k++;
        }
        ans[i][j] = (char)('0' + k);
      }
    }
  for (long long i = 0; i < (h); i++) {
    for (long long j = 0; j < (w); j++) {
      cout << ans[i][j];
    }
    cout << endl;
  }
}
