#include #include using namespace atcoder; #ifdef LOCAL #include #define dbg(...) debug::dbg(#__VA_ARGS__, __VA_ARGS__) #else #define dbg(...) void(0) #endif using namespace std; // #define int long long #define rep(i, a, b) for(int i=static_cast(a), i##_end__=static_cast(b); i < i##_end__; i++) #define rep_r(i, a, b) for(int i=static_cast(a), i##_end__=static_cast(b); i >= i##_end__; i--) #define fore(i, a) for(auto& i: a) #define all(x) std::begin(x), std::end(x) using ll = long long; // __int128; using ull = unsigned long long; template int siz(const C& c) { return static_cast(c.size()); } template constexpr int siz(const T (&)[N]) { return static_cast(N); } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template constexpr T pow2(T x){ return x * x; } template constexpr T divceil(T x, S div) { return (x % div == 0) ? x / div : (x >= 0) ? (x / div) + 1 : -((-x) / div); } template constexpr T divfloor(T x, S div){ return (x % div == 0) ? x / div : (x >= 0) ? (x / div) : -((-x) / div) - 1; } constexpr long long INF = 1LL << 60; // 1.15e18 constexpr int MOD = (int)1e9 + 7; void _main() { using mint = modint1000000007; int H, W; cin >> H >> W; vector> S1(H, vector(W)), S2(W, vector(H)); rep(y, 0, H) rep(x, 0, W){ char c; cin >> c; S1[y][x] = S2[x][y] = c; } auto func = [](int h, int w, vector>& s) -> pair { mint cnt = 1; vector chkr(2, true); // 市松模様か? rep(x, 0, w){ vector pos(2, true); // 無矛盾か? rep(y, 0, h){ if(s[y][x] == '0') pos[y % 2] = false; if(s[y][x] == '1') pos[(y + 1) % 2] = false; } if(!pos[0]) chkr[x % 2] = false; if(!pos[1]) chkr[(x + 1) % 2] = false; cnt *= (int)pos[0] + pos[1]; } return {cnt, (int)chkr[0] + chkr[1]}; }; auto [cnt1, chkr1] = func(H, W, S1); auto [cnt2, chkr2] = func(W, H, S2); assert(chkr1 == chkr2); cout << (cnt1 + cnt2 - chkr1).val() << endl; } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); _main(); }