#import <stdio.h>
#import <stdlib.h>
int H,W;
void setChar(char*A, int i, int j, char c){
    A[W*i + j] = c;
}
char getChar(char*A, int i, int j){
    if(i<0||i>=H||j<0||j>=W) {
        return '.';
    }
    return A[W*i + j];
}
int main(){
    scanf("%d %d",&H,&W);
    char *A = (char*)malloc(sizeof(char)*H*W);
    char *B = (char*)malloc(sizeof(char)*H*W);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            char c = getchar();
            if (c=='\n'){
                c = getchar();
            }
            setChar(A, i, j, c);
        }
    }
    int ans=0;
    int whiteCount;
    do{
        whiteCount = 0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                char c = getChar(A,i,j);
                if(c=='.'){
                    whiteCount++;
                    if ((getChar(A,i-1,j)=='#')||(getChar(A,i+1,j)=='#')||(getChar(A,i,j-1)=='#')||(getChar(A,i,j+1)=='#')) {
                        setChar(B, i, j, '#');
                    } else {
                        setChar(B, i, j, '.');
                    }
                } else {
                    setChar(B, i, j, '#');
                }
            }
        }
        char *tmp=B;
        B=A;
        A=tmp;
        if(whiteCount>0){
            ans++;
        }
    }while(whiteCount>0);
    printf("%d",ans);
    free(A);
    free(B);
}
