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

int main() {
  int H, W, counter;
  string s0, s1, s2, s3;
  s0 = "....................................................";
  for (int i = 0; i <= H; i++){
    if (i == 0){
      cin >> s3;
      s3 = "." + s3 + ".";
      s2 = s0;
    } else{
      counter = 0;
      s1 = s2;
      s2 = s3;
      if(i == H)
      s3 = s0;
      else{
        cin >> s3;
        s3 = "." + s3 + ".";
      }
      for (j = 1; j <= W; j++){
        if (s2.at(j) == '.'){
          if (s1.at(j - 1) == '#')
          counter++;
          if (s1.at(j) == '#')
          counter++;
          if (s1.at(j + 1) == '#')
          counter++;
          if (s2.at(j - 1) == '#')
          counter++;
          if (s2.at(j + 1) == '#')
          counter++;
          if (s3.at(j - 1) == '#')
          counter++;
          if (s3.at(j) == '#')
          counter++;
          if (s3.at(j + 1) == '#')
          counter++;
          cout << counter;
        }
        else
        cout << "#";
      }
      cout << endl;
    }
  }
}
