#include <bits/stdc++.h>
#include <vector>
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9+5;
const int mod = 1e9+7;
#define ll long long
struct mint {
  ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
 }
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
vector<mint> fac(MX);
vector<mint> ifac(MX);
mint comp(ll a, ll b) {
    return fac[a]/fac[b]/fac[a-b];
}
mint pow2[4000002];
signed main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char> > a(h);
    vector<vector<int> > u(h);
    vector<vector<int> > d(h);
    vector<vector<int> > l(h);
    vector<vector<int> > r(h);
    int clean = 0;
    pow2[0]=1;
    FOR(i,1,4000002) {
        pow2[i]=pow2[i-1]*(mint)2;
    }
    rep(i,h) {
        string s;
        cin>>s;
        rep(j,w) a[i].push_back(s[j]);
        rep(j,w) if(a[i][j]=='.') clean++;
        rep(j,w) {
            u[i].push_back(0);
            d[i].push_back(0);
            l[i].push_back(0);
            r[i].push_back(0);
        }
    }
    mint cl = clean;
    mint ans = cl * pow2[clean];
    //u
    rep(i,h) {
        rep(j,w) {
            u[i][j]=l[i][j]=0;
            if(a[i][j]=='#')continue;
            if(i>0) u[i][j]=u[i-1][j];
            if(j>0) l[i][j]=l[i][j-1];
            u[i][j]++;
            l[i][j]++;
        }
    }
    rrep(i,h) {
        rrep(j,w) {
            d[i][j]=r[i][j]=0;
            if(a[i][j]=='#')continue;
            if(i<h-1) d[i][j]=d[i+1][j];
            if(j<w-1) r[i][j]=r[i][j+1];
            d[i][j]++;
            r[i][j]++;
        }
    }
    rep(i,h) {
        rep(j,w) {
            if(a[i][j]=='#')continue;
            int don = u[i][j]+d[i][j]+r[i][j]+l[i][j]-3;
            // cout << don << endl;
            ans-= pow2[clean-don];
        }
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int64_t solve(int64_t N, string S, string T) {
    // TODO: edit here
    ll count(0);
    for (size_t i = 0; i < N; ++i) {
        if (S[i] == '1') ++count;
        if (T[i] == '1') --count;
    }
    if (count != 0) return -1;
    for (size_t i = 0; i < N; ++i) {
        if (S[i] != T[i]) {
//            cerr << S[i] << ", " << T[i] << endl;
            if (S[i] == '1') {
                for (auto j = i + 1; j < N; ++j) {
                    if (S[j] == '0') {
//                        cerr << i << ", " << j << endl;
                        S[i] = '0';
                        S[j] = '1';
                        ++count;
                        break;
                    }
                }
            } else {
                for (auto j = i + 1; j < N; ++j) {
                    if (T[j] == '0') {
//                        cerr << i << ", " << j << endl;
                        T[i] = '0';
                        T[j] = '1';
                        ++count;
                        break;
                    }
                }
            }
        }
    }
    return count;
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int64_t N;
    string S, T;
    cin >> N >> S >> T;
    auto ans = solve(N, S, T);
    cout << ans << endl;
    return 0;
}
