#!/usr/bin/env ruby

def check(i, j, max)
  @dp[i][j] = max
  (i..[i+max,@H-1].min).each do |k|
    (j..[j+max-(k-i), @W-1].min).each do |l|
      if @input[k][l] == '#'
        @dp[i][j] = [@dp[i][j], (l-j) + (k-i)].min
      end
    end
  end
end

if $0 == __FILE__
  @H, @W = gets.split(' ').map &:to_i
  @input = []
  @input = @H.times.map{ gets.chomp.split('') }
  max = @H + @W - 2

  @dp = Array.new(@H){Array.new(@W, max)}

  (0...@H).each do |i|
    (0...@W).each do |j|
      if @input[i][j] == '#'
        @dp[i][j] = 0
        next
      end

      min_candidates = [max]
      if i > 0
        min_candidates << @dp[i-1][j] + 1
      end
      if j > 0
        min_candidates << @dp[i][j-1] + 1
      end
      if i > 0 and j > 0
        min_candidates << @dp[i-1][j-1] + 2
      end

      check(i, j, min_candidates.min)
    end
  end

  puts @dp.map{|d| d.max }.max
end
