H, W = map(int, input().split()) S = [list(input().rstrip()) for _ in range(H)] T = [list(input().rstrip()) for _ in range(H)] for i in range(H): S[i] = [list(x) for x in S[i]] T[i] = [list(x) for x in T[i]] def judge(S, T): for i in range(H): for j in range(W): if S[i][j] == T[i][j]: return False return True ok1 = judge(S, T) Sr = [list(x)[::-1] for x in zip(*S)] Srr = [list(x)[::-1] for x in zip(*Sr)] ok2 = judge(Srr, T) # print(ok1, ok2) if ok1 == True and ok2 == True: e = 0 rem = 1 for i in range(10**6): p = rem * (1 - 2 ** (-i)) e += p * (i+1) rem -= p if e > 0 and e < 10**(-7): break elif ok1 == False and ok2 == False: e = 0 elif ok1 == True and ok2 == False: e = 0 rem = 1 for i in range(10**6): if i % 2 == 0: p = rem * (1 - 2 ** (-i)) else: p = 0 e += p * (i+1) rem -= p if e > 0 and e < 10**(-7): break elif ok1 == False and ok2 == True: e = 0 rem = 1 for i in range(10**6): if i % 2 == 1: p = rem * (1 - 2 ** (-i)) else: p = 0 e += p * (i+1) rem -= p if e > 0 and e < 10**(-7): break print(e)