h, w = map(int, input().split()) s = [input() for _ in range(h)] a = 1e5 for i in s: c = 0 for j in i: if j == '.' and c != 0: a = min(a, c) c = 0 if j == '#': c += 1 if c != 0: a = min(a, c) for i in range(w): c = 0 for j in range(h): k = s[j][i] if k == '.' and c != 0: a = min(a, c) c = 0 if k == '#': c += 1 if c != 0: a = min(a, c) print(a)