import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int h, w;
        h = sc.nextInt();
        w = sc.nextInt();
        char mass[][] = new char[h][w];
        for(int i = 0; i < h; i++){
            mass[i] = sc.next().toCharArray();
        }
        
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(mass[i][j] == '.'){
                    mass[i][j] = '0';
                }
            }
        }
        
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if( mass[i][j] == '#'){
                    for(int k = i - 1; k < i + 2; k++){
                        for(int l = j - 1; l < j + 2; l++){
                            if( k != -1 && k != h && l != -1 && l != w){
                                if(mass[k][l] != '#'){
                                    int num = (int) mass[k][l];
                                    mass[k][l] = (char) (num + 1);
                                }
                            }
                        }
                    }
                }
                
            }
        }
        
        for(int i = 0; i < h; i++){
            System.out.println(mass[i]);
        }
    }
    
}
