        #include <bits/stdc++.h>
        using namespace std;
         
        int main() {
        int H, W;
        cin >> H >> W;
        Matrix<int> Si(H+1,W+1);
        string s[H];
        
          for (int i = 0; i < H; i++){
            cin >> s[i];
          }
     
          for (int i = 0; i < H+1; i++){
            for (int j = 0; j < W+1; j++){
               Si[i][j]=0;
            }
          }
          
          for (int i = 0; i < H; i++){
            for (int j = 0; j < W; j++){
             if(s[i].at(j)=='#'){
               Si[i][j]++;
               Si[i][j+1]++;
               Si[i][j+2]++;
               Si[i+1][j]++;
               //Si[i+1][j+1]++;
               Si[i+1][j+2]++;
               Si[i+2][j]++;
               Si[i+2][j+1]++;
               Si[i+2][j+2]++;
             }
            }
          }
          for (int i = 0; i < H; i++){
            for (int j = 0; j < W; j++){
             if(s[i].at(j)!='#'){
               cout << Si[i+1][j+1];
             }
              else{
                cout << '#';
              }
            }
           cout << endl;
          }        
          return 0;
        }