def solve(H, W, Ss, Ts): odd = all(S + T + 1 == 1 << W for S, T in zip(Ss, Ts)) even = all(S + T + 1 == 1 << W for S, T in zip(Ss[::-1], Ts)) E = [] p = 1.0 for i in range(1, 20202020): if i & 1: if odd: e = i * p * (1.0 - pow(2, -i + 1)) E.append(e) p *= pow(2, -i + 1) else: if even: e = i * p * (1.0 - pow(2, -i + 1)) E.append(e) p *= pow(2, -i + 1) ans = sum(E[::-1]) return ans def main(): H, W = map(int, input().split()) Ss = [] for _ in range(H): line = input() line = line.replace(".", "0").replace("#", "1") Ss.append(int(line, 2)) Ts = [] for _ in range(H): line = input() line = line.replace(".", "0").replace("#", "1") Ts.append(int(line, 2)) ans = solve(H, W, Ss, Ts) print(ans) if __name__ == "__main__": main()