Z = gets.to_s.split.map &.to_u32
H = Z[0]
W = Z[1]
T = H*W
S = Array.new(H) { gets.to_s } << "#"*W
A = Array.new(T) {|i| Array.new(T-i, T)}
C = Array.new(T,0)
T.times {|i|
  h,w = i.divmod W
  a,s = A[i],S[h]
  a[0] = T
  next  if s[w] != '.'
  a[0] = 0
  a[1] = 1  if s[w+1]? == '.'
  a[W] = 1  if S[h+1][w] == '.'
}
T.times {|k|
  kh,kw = k.divmod W
  ka = A[k]
  next  if ka[0] > 0
  T.times {|i|
    ih,iw = i.divmod W
    ia = A[i]
    next  if i==k || ia[0]>0
    x = i<k ? ia[k-i] : ka[i-k]
    (i+1...T).each {|j|
      jh,jw = j.divmod W
      ja = A[j]
      next  if j==k || ja[0]>0
      y = j<k ? ja[k-j] : ka[j-k]
      z = ia[l=j-i]
      if z > (y+=x)
        C[z] -= 1  if z < T
        C[y] += 1
        ia[l] = y
      end
    }
  }
}
p (T-1).downto(0) {|i| break i if C[i]!=0 }