#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); i++)
 
int main() {
   int n,k,i,j;
   cin>>n>>k;
   char c[n][k],ans[n][k];
   rep(i,n){
     rep(j,k){
     cin>>c[i][j];
     ans[i][j]='0';
     }
   }
   rep(i,n){
     rep(j,k){
     if(i-1>=0&&j-1>0){
         ans[i-1][j-1]+=1;
         }
         if(i-1>=0){
         ans[i-1][j]+=1;
         }
         if(i-1>=0&&j+1<k){
         ans[i-1][j+1]+=1;
         }
         if(j-1>=0){
         ans[i][j-1]+=1;
         }
         if(i+1<k){
         ans[i][j+1]+=1;
         }
         if(i+1<n&&j-1>=0){
         ans[i+1][j-1]+=1;
         }
         if(i+1<n){
         ans[i+1][j]+=1;
         }
         if(i+1<n&&j+1<k){
         ans[i+1][j+1]+=1;
         }
       }
     }
   }
   rep(i,n){
     rep(j,k){
       if(c[i][j]=='#'){
         ans[i][j]='#';
       }
     }
   }
     rep(i,n){
      rep(j,k){
        cout<<ans[i][j];
      }
       cout<<endl;
     }
     return 0;
}
