//  inputに入力データ全体が入る
function Main(input) {
  var lines = input.split("\n").slice(1);
  var arr =[];
  for(var i=0;i<lines.length;i++){
    arr[i] = lines[i].split('')
  }
  var b = []
  for(i=0;i<arr.length;i++){
    for(j=0;j<arr[i].length;j++){
      if(arr[i][j]=='#'){
        b.push([i,j])
      } else if (b[0]) {
        d = Math.abs(i - b[0][0]) + Math.abs(j - b[0][1])
        arr[i][j] = d
      } else {
        arr[i][j] = 2000;
      }
    }
  }   
  max = 0
  for(i=0;i<arr.length;i++){
    for(j=0;j<arr[i].length;j++){
      if(arr[i][j]!='#'){
        for(s=0;s<b.length;s++){
          d = Math.abs(i - b[s][0]) + Math.abs(j - b[s][1])
          if (arr[i][j] > d) {
            arr[i][j] = d
            if (max>=d) {
              break;
            }
          }
        }
        if(max<arr[i][j]) { max=arr[i][j] }
      }   
    }
  }
  console.log(max)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));