h, w = read_line.split.map(&.to_i) s = Array.new(h) { read_line.chars.map { |ch| ch == '#' } } t = Array.new(h) { read_line.chars.map { |ch| ch == '#' } } ok0 = h.times.all? { |i| w.times.all? { |j| s[i][j] != t[i][j] } } s.reverse! s.map! { |r| r.reverse } ok1 = h.times.all? { |i| w.times.all? { |j| s[i][j] != t[i][j] } } if !ok0 && !ok1 puts -1 exit end ans = 0.0 fail = 1.0 prob = 1.0 100000.times do |i| if [ok0, ok1][i % 2] ans += (i + 1) * (1.0 - fail) * prob prob -= prob * (1.0 - fail) end fail *= 0.5 end printf("%.9f\n", ans)