#include <bits/stdc++.h>
using namespace std;
int main () {
    
    int h,w;
    cin >> h >> w;
    
    if (h==1 && w==1) {
        string s;
        cin >> s;
        if (s==".") cout <<0<<endl;
        else cout << "#" <<endl;
    }
    
    
    else if (h==1 && w!=1) {
        string s;
        cin >> s;
        if (s.at(0)=='.') {
            if (s.at(1)=='#') s.at(0)='1';
            else s.at(0)='0';
        }
        for (int i=0; i<w-2; i++){
            if (s.at(i+1)=='.') {
                int j=0;
                char x;
                if (s.at(i)=='#')j++;
                if (s.at(i+2)=='#')j++;
                if (j==0) x='0';
                if (j==1) x='1';
                if (j==2) x='2';
                s.at(i+1)=x;
            }
        }
        if (s.at(w-1)=='.') {
            if (s.at(w-2)=='#') s.at(w-1)='1';
            else s.at(w-1)='0';    
        }
        cout << s <<endl;                            //出力1行目
     }
    
    
    else if (h!=1 && w==1){
        string s,t,u;
        cin >> t >>u;
        if (t==".") {
            if (u=="#") cout << 1 <<endl;;
            cout << 0 <<endl;
        }
        else cout << "#" <<endl;
        
        for (int i=0; i<h-2;i++) {
            s=t;
            t=u;
            cin >>u;
            if (t==".") {
                int j=0;
                if (s=="#")j++;
                if (u=="#")j++;
                cout << j <<endl;
            }
            else cout << "#" <<endl;
        }
        
        if (u==".") {
            if (t=="#") cout << 1 <<endl;
            else cout << 0 <<endl;
        }
        else cout << "#" <<endl;
    }
    
    else {
        string s,t,u;
        cin >> t >> u ;
        if (t.at(0)=='.') {
            int j=0;
            if (t.at(1)=='#') j++;
            if (u.at(0)=='#') j++;
            if (u.at(1)=='#')j++;
            cout <<j;
        }
        else cout <<"#";
        
        for (int i=0; i<w-2;i++){
            if (t.at(i+1)=='.'){
                int j=0;
                if (t.at(i)=='#') j++;
                if (t.at(i+2)=='#')j++;
                if (u.at(i)=='#')j++;
                if (u.at(i+1)=='#')j++;
                if (u.at(i+2)=='#')j++;
                cout <<j;
            }
            else cout <<"#";
        }
        if(t.at(w-1)=='.'){
            int j=0;
            if (t.at(w-2)=='#') j++;
            if (u.at(w-2)=='#') j++;
            if (u.at(w-1)=='#')j++;
            cout <<j<<endl;
        }
        else cout << "#" <<endl;
        
        
        
        
        for (int i=0; i<h-2; i++) {
            s=t;
            t=u;
            cin >> u;
            
            if (t.at(0)=='.') {
                int j=0;
                if (s.at(0)=='#') j++;
                if (s.at(1)=='#')j++;
                if (t.at(1)=='#') j++;
                if (u.at(0)=='#') j++;
                if (u.at(1)=='#')j++;
                cout <<j;
            }
            else cout <<"#";
        
            for (int i=0; i<w-2;i++){
                if (t.at(i+1)=='.'){
                    int j=0;
                    if (s.at(i)=='#')j++;
                    if (s.at(i+1)=='#')j++;
                    if (s.at(i+2)=='#')j++;
                    if (t.at(i)=='#') j++;
                    if (t.at(i+2)=='#')j++;
                    if (u.at(i)=='#')j++;
                    if (u.at(i+1)=='#')j++;
                    if (u.at(i+2)=='#')j++;
                    cout <<j;
                }
                else cout <<"#";
            }
            if(t.at(w-1)=='.'){
                int j=0;
                if (s.at(w-2)=='#') j++;
                if (s.at(w-1)=='#')j++;
                if (t.at(w-2)=='#') j++;
                if (u.at(w-2)=='#') j++;
                if (u.at(w-1)=='#')j++;
                cout <<j<<endl;
            }
            else cout << "#" <<endl;
        }
        
        
        
        
        
        if (u.at(0)=='.') {
            int j=0;
            if (u.at(1)=='#') j++;
            if (t.at(0)=='#') j++;
            if (t.at(1)=='#')j++;
            cout <<j;
        }
        else cout <<"#";
        
        for (int i=0; i<w-2;i++){
            if (u.at(i+1)=='.'){
                int j=0;
                if (u.at(i)=='#') j++;
                if (u.at(i+2)=='#')j++;
                if (t.at(i)=='#')j++;
                if (t.at(i+1)=='#')j++;
                if (t.at(i+2)=='#')j++;
                cout <<j;
            }
            else cout <<"#";
        }
        if(u.at(w-1)=='.'){
            int j=0;
            if (u.at(w-2)=='#') j++;
            if (t.at(w-2)=='#') j++;
            if (t.at(w-1)=='#')j++;
            cout <<j<<endl;
        }
        else cout << "#" <<endl;
        
        
    }
    
    
    
    
}

Measured memory_bytes: 384