import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h=sc.nextInt(),w=sc.nextInt();
		String[] s=new String[h];
		StringBuilder[] sb=new StringBuilder[h];
		String[] ans=new String[h];
		int[] x={-1,-1,-1,0,0,1,1,1};
		int[] y={1,0,-1,1,-1,1,0,-1};

		for(int i=0;i<h;i++){
			s[i]=sc.next();
			ans[i]="";
		//j	sb[i].append(s[i]);
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				int cnt=0;
				//System.out.println("---"+i+j+"---");
				if(s[i].substring(j,j+1).equals(".")){
					for(int k=0;k<8;k++){
						int xx=j+x[k];
						int yy=i+y[k];
						//System.out.println(xx+" "+yy);
						if(xx<0||xx>=w||yy<0||yy>=h){
							continue;
						}
						if(s[yy].substring(xx,xx+1).equals("#")){
							cnt++;
						}
					}
					ans[i]+=cnt;
					//sb[i].replace(j, j+1, String.valueOf(cnt));
				}else{
					ans[i]+="#";
				}

			}
		}

		for(int i=0;i<h;i++){
				System.out.println(ans[i]);
		}
	}

}
