"use strict"
function main(arg) {
    arg = arg.trim().split("\n")
    arg.shift()
    var H = arg.length
    var W = arg[0].length
    var m1 = []
    for (var i = 0; i < arg.length; i++) {
        m1.push(arg[i].split(''))
    }
    arg = null
    var i = 0
    for (;; i++) {
        var finished = true
        var m2 = Array.from(new Array(H), () => new Array(W).fill(''));
        for (var y = 0; y < H; y++) for (var x = 0; x < W; x++) {
            if (m1[y][x] == '#') {
                m2[y][x] = '#'
                if (y - 1 >= 0 && m2[y-1][x] != '#') m2[y-1][x] = '#'
                if (y + 1 < H  && m2[y+1][x] != '#') m2[y+1][x] = '#'
                if (x - 1 >= 0 && m2[y][x-1] != '#') m2[y][x-1] = '#'
                if (x + 1 < W  && m2[y][x+1] != '#') m2[y][x+1] = '#'
            } else {
                finished = false
            }
        }
        if (finished) {
            break
        }
        m1 = Array.from(m2)
    }
    console.log(i)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
