⎕io←0
a←⍉↑⍎¨'.+'⎕s'&'⊃⎕nget'6.txt'
a-[0]←⌊/a ⍝translate to top-left limit
n←1+⌈/a ⍝size of bounding rect
i←n⊤⍳×/n ⍝lattice points
d←a∘.-⍤1⊢i ⍝deltas by x and y
d←+⌿|d ⍝manhattan distances
c←d=[1]⌊⌿d ⍝bool matrix of closest points
c←c×[1]1=+⌿c ⍝only the unambiguous
b←∨⌿(i=[0]n-1)∨i=0 ⍝bool mask of boundary points
⌈/(~⌈/b×[1]c)∧+/c
⎕off