#import <Foundation/Foundation.h>
int H,W;
void addToSet(int value, NSMutableSet *set){
    if (value>=0) {
        [set addObject:@(value)];
    }
}
void addToSetIfNotVisited(int value, NSMutableSet *set, int *visited){
    if (value>=0) {
        if (visited[value]==0) {
            [set addObject:@(value)];
        }
    }
}
int pointToValue(int i, int j){
    if(i>=0&&i<H&&j>=0&&j<W){
        return i*H + j;
    }
    return -1;
}
int main(){
    @autoreleasepool {
        scanf("%d %d",&H,&W);
        int *visited = (int*)malloc(sizeof(int)*H*W);
        NSMutableSet *nextPoints = [NSMutableSet set];
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                char c = getchar();
                if(c=='\n'){
                    c = getchar();
                }
                if(c=='#'){
                    visited[i*H+j]=1;
                    addToSetIfNotVisited(pointToValue(i-1,j), nextPoints, visited);
                    addToSetIfNotVisited(pointToValue(i+1,j), nextPoints, visited);
                    addToSetIfNotVisited(pointToValue(i,j-1), nextPoints, visited);
                    addToSetIfNotVisited(pointToValue(i,j+1), nextPoints, visited);
                }else{
                    visited[i*H+j]=0;
                }
            }
        }
        
        int ans=0;
        while([nextPoints count]>0){
            NSMutableSet *nextnextPoints = [NSMutableSet set];
            for (NSNumber *p in nextPoints){
                int value = [p intValue];
                visited[value]=1;
            }
            for (NSNumber *p in nextPoints){
                int value = [p intValue];
                int i = value/W;
                int j = value%W;
                addToSetIfNotVisited(pointToValue(i-1,j), nextnextPoints, visited);
                addToSetIfNotVisited(pointToValue(i+1,j), nextnextPoints, visited);
                addToSetIfNotVisited(pointToValue(i,j-1), nextnextPoints, visited);
                addToSetIfNotVisited(pointToValue(i,j+1), nextnextPoints, visited);
            }
            nextPoints = nextnextPoints;
            ans++;
        }
        printf("%d",ans);
    }
}
