#include <bits/stdc++.h>
using namespace std;
string s[55];
int main() {
  int i, j, n, m, ans;
  cin >> n >> m;
  ans = 0;
  for (i = 0; i <= n; i++) {
    cin >> s[i];
    s[i] = ' ' + s[i];
  }
  for (i = 1; i <= m; i++)
    for (j = 1; j <= n; j++)
      if (s[i][j] != '#') {
        if (s[i - 1][j] == '#') ans++;
        if (s[i - 1][j - 1] == '#') ans++;
        if (s[i - 1][j + 1] == '#') ans++;
        if (s[i][i - 1] == '#') ans++;
        if (s[i][i + 1] == '#') ans++;
        if (s[i + 1][i - 1] == '#') ans++;
        if (s[i + 1][i] == '#') ans++;
        if (s[i + 1][i + 1] == '#') ans++;
        s[i][j] == ans;
      }
  for (i = 1; i <= m; i++)
    for (j = 1; j <= n; j++) cout << s[i][j];
  return 0;
}
