#include <bits/stdc++.h>
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  vector< string > s (H + 2);
  s.at(0) = "..................................................";
  s.at(H + 1) = "..................................................";
  for(int i = 1; i <= H; i++){
    string t
    cin >> t;
    s.at(i) = '.' + t +'.';
  }
  for(int i = 1; i <= H; i++){
    for(int j = 1; j <= W; j++){
      if(s[i][j] == '.'){
        s[i][j] = 8 - (s[i-1][j-1] + s[i-1][j] + s[i-1][j+1] + s[i][j-1] + s[i][j+1] + s[i+1][j-1] + s[i+1][j] + s[i+1][j+1] - 8 * '#') / ('.' - '#');
      }
    }
  }
  for(int i = 1; i <= H; i++){
    cout << s.at(i).(substr(1, W);
  }
}