#include using namespace std; using ll = long long; #define ALL(v) v.begin(),v.end() #define dbg(x) cerr << #x << ": " << (x) << endl; template ostream& operator<<(ostream& os, pair& p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template void print(Iter beg, Iter end) { for (Iter itr = beg; itr != end; ++itr) { cerr << *itr << ' '; } cerr << '\n'; } int h,w; vector s,t; int main() { cin >> h >> w; s.resize(h); t.resize(h); for (int i = 0; i < h; ++i) cin >> s[i]; for (int i = 0; i < h; ++i) cin >> t[i]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) s[i][j] = (s[i][j]=='#' ? '.' : '#'); bool f1 = (s == t); reverse(ALL(s)); for (int i = 0; i < h; ++i) reverse(ALL(s[i])); bool f2 = (s == t); if (!f1 && !f2) { cout << -1 << '\n'; return 0; } double base = 1; double ans = 0; for (int t = 1; t < 60; ++t) { double p = 1.0 / (1LL << (t-1)); if (t % 2 == 1 && f1 || t % 2 == 0 && f2) { // cerr << t << " " << base * (1-p) << '\n'; ans += t * base * (1-p); base *= p; } } cout << fixed << setprecision(20) << ans << '\n'; }