#include #include #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; int main() { int h, w; cin >> h >> w; vector s(h), t(h); rep(i, 0, h) cin >> s[i]; rep(i, 0, h) cin >> t[i]; auto f = [&]() { rep(i, 0, h) rep(j, 0, w) { if (s[i][j] == '#' && t[i][j] == '#') return false; } return true; }; bool ok1 = f(); reverse(s.begin(), s.end()); bool ok2 = f(); if (!ok1 && !ok2) { cout << "-1" << endl; return 0; } double ans = 0; double sp = 0; rep(i, 1, 100) { double p = 1.0 - 1.0 / pow(2, i - 1); cerr << p << endl; if (i % 2 == 1 && ok1) { double x = (1.0 - sp) * p; ans += x * i; sp += x; } if (i % 2 == 0 && ok2) { double x = (1.0 - sp) * p; ans += x * i; sp += x; } } cout << fixed << setprecision(10) << ans << endl; }