#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int H,W;
    cin >> H >> W;
    
    vector<string> field(H);
    
    int i,j;
    
    for(i = 0 ; i < H ; i++){
        cin >> field.at(i);
        
    }
    
    
    for(i = 0 ; i < H ; i++){
        for(j = 0 ; j < W ; j++){
            
            int n = 0;
            
            if(field.at(i).at(j) == '#'){
                cout << '#';
                continue;
            }
          	
          	if(H == 1 && W ==1){
              		cout << n;
              		continue;
            }
          	
          	if(H == 1){
                	if(j == 0){
                      if(field.at(0).at(1) == '#')    n++;
                    }
                	else if(j < W - 1){
                      if(field.at(0).at(j - 1) == '#')    n++;
                      if(field.at(0).at(j + 1) == '#')    n++;
                	}
                	else if(j == W - 1){
                      if(field.at(0).at(j - 1) == '#')    n++;
                    }
              		cout << n;
              		continue;
            }
          
	         if(W == 1){
	                if(i == 0){
                      if(field.at(1).at(0) == '#')    n++;
                    }
	                else if(i < H - 1){
                      if(field.at(i - 1).at(0) == '#')    n++;
                      if(field.at(i + 1).at(0) == '#')    n++;
                	}
                	else if(i == H - 1){
                      if(field.at(i - 1).at(0) == '#')    n++;
                    }
	            	cout << n;
                	continue;
            }
          	
          
            if(i == 0){
                if(j == 0){
                    if(field.at(0).at(1) == '#')    n++;
                    if(field.at(1).at(0) == '#')    n++;
                    if(field.at(1).at(1) == '#')    n++;
                }
                else if(j < W - 1){
                    if(field.at(0).at(j - 1) == '#')    n++;
                    if(field.at(1).at(j - 1) == '#')    n++;
                    if(field.at(1).at(j) == '#')        n++;
                    if(field.at(1).at(j + 1) == '#')    n++;
                    if(field.at(0).at(j + 1) == '#')    n++;
                 
                }
                else if(j == W - 1){      	
                    if(field.at(0).at(j - 1) == '#')    n++;
                    if(field.at(1).at(j - 1) == '#')    n++;
                    if(field.at(1).at(j) == '#')        n++;
                }
                
                cout << n;
                
            }
            else if(i < H - 1){
                if(j == 0){
                    if(field.at(i - 1).at(j) == '#')    n++;
                    if(field.at(i - 1).at(j + 1) == '#')    n++;
                    if(field.at(i).at(j + 1) == '#')        n++;
                    if(field.at(i + 1).at(j) == '#')    n++;
                    if(field.at(i + 1).at(j + 1) == '#')    n++;
                }
                else if(j < W - 1){
                    if(field.at(i - 1).at(j - 1) == '#')    n++;
                    if(field.at(i - 1).at(j) == '#')        n++;
                    if(field.at(i - 1).at(j + 1) == '#')    n++;
                    if(field.at(i).at(j - 1) == '#')        n++;
                    if(field.at(i).at(j + 1) == '#')        n++;
                    if(field.at(i + 1).at(j - 1) == '#')    n++;
                    if(field.at(i + 1).at(j) == '#')        n++;
                    if(field.at(i + 1).at(j + 1) == '#')    n++;
                }
                else if(j == W - 1){
                    if(field.at(i - 1).at(j - 1) == '#')    n++;
                    if(field.at(i - 1).at(j) == '#')        n++;
                    if(field.at(i).at(j - 1) == '#')        n++;
                    if(field.at(i + 1).at(j - 1) == '#')    n++;
                    if(field.at(i + 1).at(j) == '#')    n++;
                }
                cout << n;
                
            }
            else if(i == H - 1){
                if(j == 0){
                    if(field.at(i - 1).at(0) == '#')    n++;
                    if(field.at(i - 1).at(1) == '#')    n++;
                    if(field.at(i).at(1) == '#')        n++;
                }
                else if(j < W - 1){
                    if(field.at(i - 1).at(j - 1) == '#')    n++;
                    if(field.at(i - 1).at(j) == '#')        n++;
                    if(field.at(i - 1).at(j + 1) == '#')    n++;
                    if(field.at(i).at(j - 1) == '#')        n++;
                    if(field.at(i).at(j + 1) == '#')        n++;
                }
                else if(j == W - 1){
                    if(field.at(i - 1).at(j - 1) == '#')    n++;
                    if(field.at(i - 1).at(j) == '#')        n++;
                    if(field.at(i).at(j - 1) == '#')        n++;
                }
                
                cout << n;
                
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256