#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int h,w;
  cin >> h >> w;
  
  bool f[h][w] = {};
  rep(i,0,h){
    string s;
    cin >> s;
    rep(j,0,w){
      if(s[j] == '#')
        f[i][j] = true;
      else
        f[i][j] = false;
    }
  }
  
  int ans[h][w] = {};

  rep(i,0,h){
    rep(j,0,w){
      int sum = 0;
      //printf("i:%d j:%d \n",i,j);

      if(!f[h][w]){
        
        if(i > 0){
          if(j > 0 )    
            if(f[i-1][j-1]){
              sum++;
              //cout << "done 1" << endl;
            }
              
          if(f[i-1][j]){
            sum++;
            //P("done 2");
          }

          if(j < w-1)
            if(f[i-1][j+1]){
              sum++;
              //P("done 3");
            }
        }
        
        if(j > 0){
          if(f[i][j-1]){
            sum++;
            //P("done 4");
          }
        }

        if(j < w-1){
          if(f[i][j+1]){
            sum++;
            //P("done 5");
          }
        }
        
        if(i < h-1){
          if(j > 0)
            if(f[i+1][j-1]){
              sum++;
              //P("done 6");
            }
        

          if(f[i+1][j]){
            sum++;
            //P("done 7");
          }

          if(j < w-1){
            if(f[i+1][j+1]){
              sum++;
              //P("done 8");
            }
          }
        }
      
      }

    ans[i][j] = sum;
    }
  }

  rep(i,0,h){
    rep(j,0,w){
      if(f[i][j])
        cout << "#";
      else
        cout << ans[i][j];
    }
    cout << endl;
  }
  ret 0;
}