"use strict"
function main(arg) {
    // arg = arg.split("#").join(0)
    // arg = arg.split(".").join(1)
    arg = arg.trim().split("\n")
    arg.shift()
    // arg = arg.map(e => Array.from(e.split('')))
    var H = arg.length
    var W = arg[0].length
    // var m0 = Array.from(new Array(H), () => new Array(W).fill(0));
    // for (var y = 0; y < H; y++) for (var x = 0; x < W; x++) {
    //     m0[y][x] = arg[y][x]
    // }
    var m1 = []
    for (var i = 0; i < arg.length; i++) {
        m1.push(arg[i].split(''))
    }
    // current
    // var m1 = Array.from(m0)
    // next
    // var m2 = Array.from(m0)
    var i = 1
    for (; i < 100; i++) {
        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++) {
            // console.log(JSON.stringify(m2))
            if (m1[y][x] == '#') {
                m2[y][x] = '#'
                if (y - 1 >= 0) m2[y-1][x] = '#'
                if (y + 1 < H) m2[y+1][x] = '#'
                if (x - 1 >= 0) m2[y][x-1] = '#'
                if (x + 1 < W) m2[y][x+1] = '#'
            }
        }
        var l = m2.map(e => e.join('')).join('').split('#').length - 1
        // console.log(m2.map(e => e.join('')).join('').split('#'))
        // console.log(m2.map(e => e.join('')).join('').split('#').length - 1)
        if (l === W * H) {
            break
        }
        m1 = Array.from(m2)
    }
    console.log(i)
    // console.log(JSON.stringify(m2))
    // console.log(m2.map(e => e.join('')).join('\n'))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));