#include <bits/stdc++.h>
using namespace std;
#define pii             pair<int , int >
#define inf             1111111111
#define in(a)           scanf("%d", &a)
#define ins(a)          scanf("%s", a)
#define in2(a, b)       scanf("%d%d", &a, &b)
#define in3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pn              printf("\n")
#define pr(a)           printf("%d\n", a)
#define prs(a)          printf("%d ", a)
#define pr2(a, b)       printf("%d %d\n", a, b)
#define pr3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define pcs(a)          printf("Case %d: ", a)
#define mp              make_pair
#define vi              vector<int >
#define _ceil(n, a)     ((n)%(a)==0?((n)/(a)):((n)/(a)+1))
#define cl              clear()
#define sz              size()
#define pb              push_back
#define mem(a, b)       memset((a), (b), sizeof(a))
#define all(X)          (X).begin(), (X).end ()
#define iter(it, X)     for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#define ext(a)          {printf("%s\n", a); return 0;}
#define oka(x, y)       ((x)>=0&&(x)<row&&(y)>=0&&(y)<col)
#define x               first
#define y               second
#define lc              (2*i)
#define rc              (2*i+1)

typedef long long LL;
int  dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int  dx[]={1,1,0,-1,-1,-1,0,1,0};int dy[]={0,1,1,1,0,-1,-1,-1,0};//8 direction
//int  dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//bool check(int n, int pos) {return (n & (1<<pos))>>pos;} //typecast 1 in case of int
//int  on(int n, int pos) {return n | (1<<pos);} //typecast 1 in case of int
//int  off(int n, int pos) {return n & ~(1<<pos);} //typecast 1 in case of int
//bool operator < (const data &d) const{return cost<d.cost;} //reverse in priority queue

const int M = 500010;

int A[100][100];
int cnt[100][100];
int row, col;

struct data {
    int x, y, c;
    data(int u = 0, int v = 0, int w = 0) {x = u; y = v; c = w;}
    bool operator < (const data &d) const{
        if (c == d.c)
        {
            if (x == d.x) return y < d.y;
            else return x < d.x;
        }
        else return c > d.c;
    }
};

set<data>S;
char str[M];

bool ok(int x, int y)
{
    if (A[x][y] == 1)
    {
        if (A[x-1][y] == 1 || A[x-1][y] == 4) return false;
        if (A[x][y-1] == 1 || A[x][y-1] == 2) return false;
        if (A[x+1][y] == 1 || A[x+1][y] == 4) return false;
        if (A[x][y+1] == 1 || A[x][y+1] == 2) return false;
    }
    else if (A[x][y] == 2)
    {
        if (A[x][y-1] == 1 || A[x][y-1] == 2) return false;
        if (A[x+1][y] == 2 || A[x+1][y] == 3) return false;
        if (A[x][y+1] == 1 || A[x][y+1] == 2) return false;
        if (A[x-1][y] == 2 || A[x-1][y] == 3) return false;
    }
    else if (A[x][y] == 3)
    {
        if (A[x+1][y] == 2 || A[x+1][y] == 3) return false;
        if (A[x][y+1] == 3 || A[x][y+1] == 4) return false;
        if (A[x-1][y] == 2 || A[x-1][y] == 3) return false;
        if (A[x][y-1] == 3 || A[x][y-1] == 4) return false;
    }
    else if (A[x][y] == 4)
    {
        if (A[x][y+1] == 3 || A[x][y+1] == 4) return false;
        if (A[x-1][y] == 1 || A[x-1][y] == 4) return false;
        if (A[x][y-1] == 3 || A[x][y-1] == 4) return false;
        if (A[x+1][y] == 1 || A[x+1][y] == 4) return false;
    }
    return true;
}

bool place(int x, int y)
{
    assert(A[x][y] == 0);
    for (int i = 1; i <= 4; i++)
    {
        A[x][y] = i;
        if (ok(x, y)) break;
    }
    if (A[x][y] == 0) return false;

    S.erase(data(x, y, cnt[x][y]));
//    prr("assigned", x, y, "type", A[x][y]);
//    prr("erasing", x, y, cnt[x][y]);

    for (int i = 0; i < 4; i++)
    {
        int xx = x + dx[i];
        int yy = y + dy[i];
        set<data>::iterator it = S.find(data(xx, yy, cnt[xx][yy]));
        if (it != S.end())
        {
            data t = *it;
            S.erase(it);
            t.c++;
            cnt[t.x][t.y] = t.c;
            S.insert(t);

//            prr("--erasing", t.x, t.y, t.c-1);
//            prr("-----adding", t.x, t.y, t.c);
        }
    }

    return true;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("/home/riaz/Documents/in.txt", "r", stdin);
//    freopen("/home/riaz/Documents/in.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);

    int i, j, k;

    in2(row, col);
    for (i = 1; i <= row; i++)
    {
        ins(str);
        for (j = 1; j <= col; j++)
        {
            if (str[j-1] == '.') A[i][j] = 0;
            else A[i][j] = str[j-1] - '0';
        }
    }

    for (i = 1; i <= row; i++)
    {
        for (j = 1; j <= col; j++)
        {
            if (A[i][j] == 0)
            {
                int sum = 0;
                for (k = 0; k < 4; k++)
                {
                    int ii = i + dx[k];
                    int jj = j + dy[k];
                    sum += (A[ii][jj] != 0);
                }
                cnt[i][j] = sum;
                S.insert(data(i, j, sum));
            }
            else
            {
                if (!ok(i, j))
                {
                    pr(0);
                    return 0;
                }
            }
        }
    }

    int ans = 1;
    while (!S.empty())
    {
        data t = *S.begin();
//        prr(t.x, t.y, t.c);

        if (t.c == 0) ans *= 4;
        else if (t.c == 1) ans *= 2;
        ans %= 1000003;

        if (!place(t.x, t.y))
        {
            pr(0);
//            prr("failed to place", t.x, t.y, t.c);
            return 0;
        }
    }

    pr(ans);

return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pii             pair<int , int >
#define inf             1111111111
#define in(a)           scanf("%d", &a)
#define ins(a)          scanf("%s", a)
#define in2(a, b)       scanf("%d%d", &a, &b)
#define in3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pn              printf("\n")
#define pr(a)           printf("%d\n", a)
#define prs(a)          printf("%d ", a)
#define pr2(a, b)       printf("%d %d\n", a, b)
#define pr3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define pcs(a)          printf("Case %d: ", a)
#define mp              make_pair
#define vi              vector<int >
#define _ceil(n, a)     ((n)%(a)==0?((n)/(a)):((n)/(a)+1))
#define cl              clear()
#define sz              size()
#define pb              push_back
#define mem(a, b)       memset((a), (b), sizeof(a))
#define all(X)          (X).begin(), (X).end ()
#define iter(it, X)     for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#define ext(a)          {printf("%s\n", a); return 0;}
#define oka(x, y)       ((x)>=0&&(x)<row&&(y)>=0&&(y)<col)
#define x               first
#define y               second
#define lc              (2*i)
#define rc              (2*i+1)

typedef long long LL;
int  dx[]={-1, 0, 1, 0, -1};int dy[]={0, 1, 0, -1, 0}; //4 Direction
//int  dx[]={1,1,0,-1,-1,-1,0,1,0};int dy[]={0,1,1,1,0,-1,-1,-1,0};//8 direction
//int  dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//bool check(int n, int pos) {return (n & (1<<pos))>>pos;} //typecast 1 in case of int
//int  on(int n, int pos) {return n | (1<<pos);} //typecast 1 in case of int
//int  off(int n, int pos) {return n & ~(1<<pos);} //typecast 1 in case of int
//bool operator < (const data &d) const{return cost<d.cost;} //reverse in priority queue

const int M = 500010;

vector < vector < int > > A, dir;
int row, col;
char str[M];

bool ok()
{
    int i, j, k;

    for (i = 1; i <= row; i++) for (j = 1; j <= col; j++) dir[i][j] = -1;
    for (i = 1; i <= row; i++)
    {
        for (j = 1; j <= col; j++)
        {
            if (A[i][j] == 1 || A[i][j] == 2) dir[i][j] = 1;
            else if (A[i][j] == 3 || A[i][j] == 4) dir[i][j] = 0;
        }
    }

    for (i = 1; i <= row; i++)
    {
        int c = 0;
        for (j = 1; j <= col; j++) if (dir[i][j] != -1) {c = j; break;}
        if (c)
        {
            for (j = c + 1; j <= col; j++)
            {
                if (dir[i][j] == -1) dir[i][j] = dir[i][j-1] ^ 1;
                else if (dir[i][j] == dir[i][j-1]) return 0;
            }
            for (j = c - 1; j >= 1; j--)
            {
                if (dir[i][j] == -1) dir[i][j] = dir[i][j+1] ^ 1;
                else if (dir[i][j] == dir[i][j+1]) return 0;
            }
        }
    }

    for (i = 1; i <= row; i++) for (j = 1; j <= col; j++) dir[i][j] = -1;
    for (i = 1; i <= row; i++)
    {
        for (j = 1; j <= col; j++)
        {
            if (A[i][j] == 1 || A[i][j] == 4) dir[i][j] = 1;
            else if (A[i][j] == 2 || A[i][j] == 3) dir[i][j] = 0;
        }
    }

    for (j = 1; j <= col; j++)
    {
        int r = 0;
        for (i = 1; i <= row; i++) if (dir[i][j] != -1) {r = i; break;}
        if (r)
        {
            for (i = r + 1; i <= row; i++)
            {
                if (dir[i][j] == -1) dir[i][j] = dir[i-1][j] ^ 1;
                else if (dir[i][j] == dir[i-1][j]) return 0;
            }
            for (i = r - 1; i >= 1; i--)
            {
                if (dir[i][j] == -1) dir[i][j] = dir[i+1][j] ^ 1;
                else if (dir[i][j] == dir[i+1][j]) return 0;
            }
        }
    }

    return 1;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("/home/riaz/Documents/in.txt", "r", stdin);
//    freopen("/home/riaz/Documents/in.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);

    int i, j, k;

    in2(row, col);

    A.resize(row+2);
    dir.resize(row+2);
    for (i = 0; i < row+2; i++) A[i].resize(col+2), dir[i].resize(col+2);

    for (i = 1; i <= row; i++)
    {
        ins(str);
        for (j = 1; j <= col; j++)
        {
            if (str[j-1] == '.') A[i][j] = 0;
            else A[i][j] = str[j-1] - '0';
        }
    }

    if (!ok()) ext("0");

    int sum = 0;
    for (i = 1; i <= row; i++)
    {
        bool f = false;
        for (j = 1; j <= col; j++)
        {
            if (A[i][j]) f = true;
        }
        sum += (!f);
    }

    for (i = 1; i <= col; i++)
    {
        bool f = false;
        for (j = 1; j <= row; j++)
        {
            if (A[j][i]) f = true;
        }
        sum += (!f);
    }

    int ans = 1;
    while (sum--)
    {
        ans *= 2;
        ans %= 1000003;
    }

    pr(ans);

return 0;
}


#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 500005
#define MOD 1000003
char s[N];
int h[N][2],l[N][2];
int i,j,k,n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++){scanf("%s",s);
		for(j=0;j<m;j++){
			if(s[j]=='.')continue;
			k=s[j]-48;
			h[i][(k<3)^(j&1)]=1;
			l[j][(k>1&&k<4)^(i&1)]=1;
		}
	}int ans=1;
	for(i=0;i<n;i++)ans=ans*(2-h[i][0]-h[i][1])%MOD;
	for(i=0;i<m;i++)ans=ans*(2-l[i][0]-l[i][1])%MOD;
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string.h>
#include <limits.h>
#include <cfloat>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
#define read(a) a=getInt()
#define En printf("\n")
#define P(a) printf("%d ",a)
#define Pn(a) printf("%d\n",a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define rep(flag, a, b) for (int flag = (a); flag <= (b); ++flag)
#define Rep(flag, a, b) for (int flag = (a); flag >= (b); --flag)

vector<vector<char> > mm;
vector<vector<int> > rr, cc;
int n, m;
typedef long long ll;
const ll MOD = 1000003;
ll powMod(ll a, ll b) {
    if (b == 0) return 1;
    else {
        ll tmp = powMod(a, b / 2);
        if (b % 2 == 0) return tmp * tmp % MOD;
        else return tmp * tmp % MOD * a % MOD;
    }
}

int main() {
    scanf("%d%d\n", &n, &m);
    mm.resize(n);
    for (int i = 0; i < n; i++) mm[i].resize(m);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) scanf("%c", &mm[i][j]);
        getchar();
    }
    rr.resize(n);
    for (int i = 0; i < n; i++) rr[i].resize(m, 0);
    cc.resize(n);
    for (int i = 0; i < n; i++) cc[i].resize(m, 0);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (mm[i][j] != '.') {
                if (mm[i][j] <= '2') rr[i][j] = 1;
                else rr[i][j] = 2;
            }
        }
    }
    for (int j = 0; j < m; j++) {
        for (int i = 0; i < n; i++) {
            if (mm[i][j] != '.') {
                if (mm[i][j] == '1' || mm[i][j] == '4') cc[i][j] = 1;
                else cc[i][j] = 2;
            }
        }
    }
    bool gok = 1;
    int kh = 0, kc = 0;
    for (int i = 0; i < n; i++) {
        bool ok = 1;
        for (int j = 0; j < m; j++) {
            if (rr[i][j] != 0) {
                ok = 0; break;
            }
        }
        if (ok) kh++;
        else {
            bool check = 1;
            int yf = -1;
            for (int j = 0; j < m; j++) {
                if (rr[i][j] != 0) {
                    if (yf == -1) {
                        yf = rr[i][j];
                    } else {
                        if (yf != rr[i][j]) {
                            check = 0; break;
                        }
                    }
                }
                if (yf == 1) yf = 2;
                else if (yf == 2) yf = 1;
            }
            if (check == 0) {
                gok = 0; break;
            }
        }
    }
    if (!gok) Pn(0);
    else {
        for (int j = 0; j < m; j++) {
            bool ok = 1;
            for (int i = 0; i < n; i++) {
                if (rr[i][j] != 0) {
                    ok = 0; break;
                }
            }
            if (ok) kc++;
            else {
                bool check = 1;
                int yf = -1;
                for (int i = 0; i < n; i++) {
                    //printf("%d ", cc[i][j]);
                    if (rr[i][j] != 0) {
                        if (yf == -1) {
                            yf = cc[i][j];
                        } else {
                            if (yf != cc[i][j]) {
                                check = 0; break;
                            }
                        }
                    }
                    if (yf == 1) yf = 2;
                    else if (yf == 2) yf = 1;
                }
                if (check == 0) {
                    gok = 0; break;
                }
            }
        }
        //printf("%d %d\n", kh, kc);
        if (!gok) Pn(0);
        else {
            printf("%lld\n", powMod(2, kc + kh));
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;

const int mod = 1000003;

ll power(ll a, ll b, ll c = mod) {//returns a^b mod c
    if (b <= 0) return 1;
    ll temp = power(a, b / 2, c) % c;
    if (b % 2 == 0) {
        return (temp * temp) % c;
    }
    return (((a * temp) % c) * temp) % c;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<string> arr(n);
    for(int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    vector<int> rows(n, -1), cols(m, -1);
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            bool check = false;
            int rowVal, colVal;
            if(arr[i][j] == '1') {
                check = true;
                rowVal = (j%2 == 1);
                colVal = (i%2 == 1);
            } else if(arr[i][j] == '2') {
                check = true;
                rowVal = (j%2 == 1);
                colVal = (i%2 == 0);
            } else if(arr[i][j] == '3') {
                check = true;
                rowVal = (j%2 == 0);
                colVal = (i%2 == 0);
            } else if(arr[i][j] == '4') {
                check = true;
                rowVal = (j%2 == 0);
                colVal = (i%2 == 1);
            }
            if(check && rows[i] != -1 && rows[i] != rowVal) {
                cout << "0\n";
                return 0;
            }
            if(check)
                rows[i] = rowVal;
            if(check && cols[j] != -1 && cols[j] != colVal) {
                cout << "0\n";
                return 0;
            }
            if(check)
                cols[j] = colVal;
        }
    }
    int cnt = 0;
    for(int i = 0; i < n; ++i) {
        if(rows[i] == -1) cnt++;
    }
    for(int j = 0; j < m; ++j) {
        if(cols[j] == -1) cnt++;
    }
    cout << power(2, cnt) << '\n';
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define TASK ""
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define for1(i, n) for (int i = 1; i <= (int)n; i++)
#define X first
#define Y second
#define mk make_pair
#define pk push_back
#define all(v) v.begin(), v.end()
#define TIME clock() * 1.0 / CLOCKS_PER_SEC

const double EPS = 1e-15;
const double PI = acos(-1.0);
const int MAXN = (int)5e5 + 7;
const int LOGN = 20;
const int INF = (int)1e9 + 7;
const ll LINF = (ll)4e18 + 7;
const int MOD = (int)1e6 + 3;
const ull P = 239017;
const ull MM = (ull)2147482661;
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

int solve();

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#else
	//freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
#endif
	return solve();
}

void no() {
	cout << 0;
	exit(0);
}

int str[MAXN], col[MAXN];

void upd(int &x, int y) {
	if (x != -1 && x != y) no();
	x = y;
	return;
}

int solve()
{
	int n, m;
	cin >> n >> m;
	forn(i, n) str[i] = -1;
	forn(j, m) col[j] = -1;
	forn(i, n) {
		scanf("\n");
		forn(j, m) {
			const char c = getchar();
			if (c == '.') continue;
			if (c == '1') {
				upd(col[j], 1 ^ (i & 1));
				upd(str[i], 1 ^ (j & 1));
			}
			if (c == '2') {
				upd(col[j], 0 ^ (i & 1));
				upd(str[i], 1 ^ (j & 1));
			}
			if (c == '3') {
				upd(col[j], 0 ^ (i & 1));
				upd(str[i], 0 ^ (j & 1));
			}
			if (c == '4') {
				upd(col[j], 1 ^ (i & 1));
				upd(str[i], 0 ^ (j & 1));
			}
		}
	}
	int answer = 1;
	forn(i, n) {
		if (str[i] == -1) {
			answer <<= 1;
			if (answer >= MOD) answer -= MOD;
		}
	}
	forn(j, m) {
		if (col[j] == -1) {
			answer <<= 1;
			if (answer >= MOD) answer -= MOD;
		}
	}
	cout << answer;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define forall(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define dforn(i, n) for(int i = ((int) n) - 1; i >= 0; i--)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
typedef long long ll;
const int MAXN = -1, MOD = 1000003;

ll n, m;
vector<string> board;
ll Ans;

#define en(a, b, c) (a <= b && b <= c)
int main(){
	while(cin >> n >> m){
        Ans = 1; board.resize(n);
        forn(i, n)cin >> board[i];
        forn(i, n){
            bool e[2] = {1, 1};
            forn(j, m)if(board[i][j] != '.'){
                int t = board[i][j] - '1';
                e[(t/2) xor (j%2)] = false;
            }
            Ans = Ans*((int) e[0] + (int) e[1]) %MOD;
        }
        forn(j, m){
            bool e[2] = {1, 1};
            forn(i, n)if(board[i][j] != '.'){
                int t = board[i][j] - '1';
                e[en(1, t, 2) xor (i%2)] = false;
            }
            Ans = Ans*((int) e[0] + (int) e[1]) %MOD;
        }
        printf("%lld\n", Ans);
	}
	return 0;
}


#include <bits/stdc++.h>

#define lli long long int
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define mp make_pair
#define fin freopen( "input.txt", "r", stdin );
#define fout freopen( "output.txt", "w", stdout );

const int N = 155;

using namespace std;

int n;
int m;
vector < vector < int > > d;
vector < vector < char > > c;

int main()
{
    //fin("input.txt");
    //fout("output.txt");
    cin >> n >> m;
    c.resize(n + 3);
    d.resize(n + 3);
    for(int i = 0; i <= n + 2; i++){
        c[i].resize(m + 3);
        d[i].resize(m + 3);
        for(int j = 0; j <= m + 2; j++)
            d[i][j] = 0;
    }
    int ans = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> c[i][j];
            if(c[i][j] == '1'){
                d[i - 1][j] |= 1;
                d[i][j - 1] |= 8;
            }
            if(c[i][j] == '2'){
                d[i + 1][j] |= 4;
                d[i][j - 1] |= 8;
            }
            if(c[i][j] == '3'){
                d[i + 1][j] |= 4;
                d[i][j + 1] |= 2;
            }
            if(c[i][j] == '4'){
                d[i - 1][j] |= 1;
                d[i][j + 1] |= 2;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(d[i][j] == 5 || d[i][j] == 10)
                ans = 0;
            if(c[i][j] == '1' && (d[i][j] & 9))
                ans = 0;
            if(c[i][j] == '2' && (d[i][j] & 12))
                ans = 0;
            if(c[i][j] == '3' && (d[i][j] & 6))
                ans = 0;
            if(c[i][j] == '4' && (d[i][j] & 3))
                ans = 0;
        }
    }
    for(int i = 1; i <= n; i++){
        bool b = true;
        for(int j = 1; j <= m; j++)
            if(c[i][j] != '.')
                b = false;
        if(b)
            ans = (ans * 2) % 1000003;
    }
    for(int i = 1; i <= m; i++){
        bool b = true;
        for(int j = 1; j <= n; j++)
            if(c[j][i] != '.')
                b = false;
        if(b)
            ans = (ans * 2) % 1000003;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

#define lli long long int
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define mp make_pair
#define fin freopen( "input.txt", "r", stdin );
#define fout freopen( "output.txt", "w", stdout );

const int N = 500500;

using namespace std;

int n;
int m;
int d1[N];
int d2[N];
vector < vector < char > > c;

int main()
{
    //fin("input.txt");
    //fout("output.txt");
    cin >> n >> m;
    c.resize(n + 3);
    for(int i = 0; i <= n + 2; i++)
        c[i].resize(m + 3);
    int ans = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> c[i][j];
            if(c[i][j] == '.')
                continue;
            int x = (j + 1) % 2,
                y = (i + 1) % 2;
            if(c[i][j] == '1' || c[i][j] == '2')
                x = j % 2;
            if(c[i][j] == '1' || c[i][j] == '4')
                y = i % 2;
            if(!d1[i])
                d1[i] = x;
            if(!d2[j])
                d2[j] = y;
            if(d1[i] != x || d2[j] != y)
                ans = 0;
        }
    }
    for(int i = 1; i <= n; i++){
        bool b = true;
        for(int j = 1; j <= m; j++)
            if(c[i][j] != '.')
                b = false;
        if(b)
            ans = (ans * 2) % 1000003;
    }
    for(int i = 1; i <= m; i++){
        bool b = true;
        for(int j = 1; j <= n; j++)
            if(c[j][i] != '.')
                b = false;
        if(b)
            ans = (ans * 2) % 1000003;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

#define lli long long int
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define mp make_pair
#define fin freopen( "input.txt", "r", stdin );
#define fout freopen( "output.txt", "w", stdout );

const int N = 500500;

using namespace std;

int n;
int m;
int d1[N];
int d2[N];
vector < vector < char > > c;

int main()
{
    //fin("input.txt");
    //fout("output.txt");
    cin >> n >> m;
    c.resize(n + 3);
    for(int i = 0; i <= n + 2; i++)
        c[i].resize(m + 3);
    for(int i = 0; i <= max(n, m); i++)
        d1[i] = d2[i] = -1;
    int ans = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> c[i][j];
            if(c[i][j] == '.')
                continue;
            int x = (j + 1) % 2,
                y = (i + 1) % 2;
            if(c[i][j] == '1' || c[i][j] == '2')
                x = j % 2;
            if(c[i][j] == '1' || c[i][j] == '4')
                y = i % 2;
            if(d1[i] == -1)
                d1[i] = x;
            if(d2[j] == -1)
                d2[j] = y;
            if(d1[i] != x || d2[j] != y)
                ans = 0;
        }
    }
    for(int i = 1; i <= n; i++){
        bool b = true;
        for(int j = 1; j <= m; j++)
            if(c[i][j] != '.')
                b = false;
        if(b)
            ans = (ans * 2) % 1000003;
    }
    for(int i = 1; i <= m; i++){
        bool b = true;
        for(int j = 1; j <= n; j++)
            if(c[j][i] != '.')
                b = false;
        if(b)
            ans = (ans * 2) % 1000003;
    }
    cout << ans << endl;
}


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

long long fast_pow(long long base, long long power)
{
	if(power==0)
		return 1;
	if(power==1)
		return base;
	long long ans = 1;
	if(power%2)
	{
		ans *= base;
		ans %= MOD;
	}

	long long temp = fast_pow(base, power/2);
	ans *= (temp*temp)%MOD;
	ans %= MOD;
	return ans;
}

int main()
{
	int n, m;
	cin>>n>>m;
	char g[n][m];
	for(int i=0; i<n; ++i)
	{
		for(int j=0; j<m; ++j)
		{
			cin>>g[i][j];
		}
	}

	int r=0, c=0;

	for(int i=0; i<n; ++i)
	{
		int lr=0;
		for(int j=0; j<m; ++j)
		{
			lr *= -1;
			if(g[i][j]!='.')
			{
				if(lr==0)
				{
					if(g[i][j]=='1'||g[i][j]=='2')
						lr=-1;
					else
						lr=1;
				}
				else
				{
					if(g[i][j]=='1'||g[i][j]=='2')
					{
						if(lr==1)
						{
							cout<<0;
							return 0;
						}
					}
					else
					{
						if(lr==-1)
						{
							cout<<0;
							return 0;
						}
					}

				}
			}
		}
		if(lr==0)
			++r;
	}

	for(int j=0; j<m; ++j)
	{
		int ud=0;
		for(int i=0; i<n; ++i)
		{
			ud *= -1;
			if(g[i][j]!='.')
			{
				if(ud==0)
				{
					if(g[i][j]=='1'||g[i][j]=='4')
						ud=-1;
					else
						ud=1;
				}
				else
				{

					if(g[i][j]=='1'||g[i][j]=='4')
					{
						if(ud==1)
						{
							cout<<0;
							return 0;
						}
					}
					else
					{
						if(ud==-1)
						{
							cout<<0;
							return 0;
						}
					}
				}
			}
		}
		if(ud==0)
			++c;
	}
	//cout<<"r="<<r<<"c="<<c<<endl;
	cout<<fast_pow(2, r+c)<<endl;
	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ull  unsigned long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 600000;
string s[N];
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, m;
    cin >> n >> m;
    int ans = 1;
    int mod = 1e6 + 3;
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 0; i < n; i++){
        int t = -1;
        int f = 1;
        for (int j = 0; j < m; j++){
            if (s[i][j] != '.'){
                int p = 0;
                if (s[i][j] == '1' || s[i][j] ==  '2') p = j % 2; else p = ((j % 2) ^ 1);
                if (p != t && t != -1) f = 0; else t = p;
            }
        }
        if (f == 0){
            cout << 0;
            return 0;
        }
        if (t == -1)
        ans = (ans + ans) % mod;
    }
    for (int j = 0; j < m; j++){
        int t = -1;
        int f = 1;
        for (int i = 0; i < n; i++){
            if (s[i][j] != '.'){
                int p = 0;
                if (s[i][j] == '1' || s[i][j] == '4') p = i % 2; else p = (i % 2) ^ 1;
                if (p != t && t != -1) f = 0; else t = p;
            }
        }
        if (f == 0){
            cout << 0;
            return 0;
        }
        if (t == -1)
        ans = (ans + ans) % mod;
    }
    cout << ans;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ull  unsigned long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 600000;
string s[N];
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, m;
    cin >> n >> m;
    int ans = 1;
    int mod = 1e6 + 3;
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 0; i < n; i++){
        int t = -1;
        int f = 1;
        for (int j = 0; j < m; j++){
            if (s[i][j] != '.'){
                int p = 0;
                if (s[i][j] == '1' || '2') p = i % 2; else p = (i % 2) ^ 1;
                if (p != t && t != -1) f = 0; else t = p;
            }
        }
        if (f == 0){
            cout << 0;
            return 0;
        }
        if (t == -1)
        ans = (ans + ans) % mod;
    }
    for (int j = 0; j < m; j++){
        int t = -1;
        int f = 1;
        for (int i = 0; i < n; i++){
            if (s[i][j] != '.'){
                int p = 0;
                if (s[i][j] == '1' || '4') p = i % 2; else p = (i % 2) ^ 1;
                if (p != t && t != -1) f = 0; else t = p;
            }
        }
        if (f == 0){
            cout << 0;
            return 0;
        }
        if (t == -1)
        ans = (ans + ans) % mod;
    }
    cout << ans;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int mod = 1000003;
const int Maxd = 4;
const int dh[Maxd] = {0, 0, 1, 1};
const int dv[Maxd] = {0, 1, 1, 0};

int n, m;
vector <pair <int, int> > h, v;

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin >> n >> m; cin.ignore();
    h.resize(n); fill(h.begin(), h.end(), make_pair(-1, -1));
    v.resize(m); fill(v.begin(), v.end(), make_pair(-1, -1));
    bool pos = true;
    for (int i = 0; i < n && pos; i++)
        for (int j = 0; j < m && pos; j++) {
            char c; cin >> c;
            if (c == '.') continue;
            int curh = dh[c - '1'], curv = dv[c - '1'];
            if (h[i].first == -1) h[i] = make_pair(j, curh);
            if (v[j].first == -1) v[j] = make_pair(i, curv);
            pos = (h[i].second + j - h[i].first) % 2 == curh &&
                  (v[j].second + i - v[j].first) % 2 == curv;
        }
    if (!pos) cout << "0\n";
    else {
         int res = 1;
         for (int i = 0; i < n; i++)
             if (h[i].first == -1) res = 2 * res % mod;
         for (int i = 0; i < m; i++)
             if (v[i].first == -1) res = 2 * res % mod;
         cout << res << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int mod = 1e6 + 3;
int n, m;
int main() {
	ios::sync_with_stdio(false);
	vector <string> a;
	string s;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> s;
		a.push_back(s);
	}
	long long res = 1;
	for (int i = 0; i < n; i++) {
		int p = 0, q = 0;
		for (int j = 0; j < m; j++) {
			if (a[i][j] == '.') continue;
			if ((j % 2 == 1) ^ (a[i][j] == '3' || a[i][j] == '4')) p = 1;
			else q = 1;
		}
		if (p && q) res = 0;
		if (p + q == 0) res = (res + res) % mod;
	}
	for (int j = 0; j < m; j++) {
		int p = 0, q = 0;
		for (int i = 0; i < n; i++) {
			if (a[i][j] == '.') continue;
			if ((i % 2 == 1) ^ (a[i][j] == '1' || a[i][j] == '4')) p = 1;
			else q = 1;
		}
		if (p && q) res = 0;
		if (p + q == 0) res = (res + res) % mod;
	}
	cout << res;
}


import java.io.*;
import java.util.*;
public class c {
public static void main(String[] args) throws IOException {
	input.init(System.in);
	PrintWriter out = new PrintWriter(System.out);
	int n = input.nextInt(), m = input.nextInt();
	char[][] grid = new char[n][m];
	for(int i = 0; i<n; i++) grid[i] = input.next().toCharArray();
	long mod = (long)1e6+3;
	long pow = 1;
	boolean good = true;
	for(int i = 0; i<n; i++)
	{
		boolean empty = true;
		boolean typea = false, typeb = false;
		for(int j = 0; j<m; j++)
			if(grid[i][j] != '.')
			{
				int type = grid[i][j] - '0';
				if(j%2 == 0 && type <= 2 || j%2 == 1 && type > 2) typea = true;
				else typeb = true;
				empty = false;
			}
		if(empty) pow = (pow*2)%mod;
		if(typea && typeb) good = false;
	}
	for(int j = 0; j<m; j++)
	{
		boolean empty = true, typea = false, typeb = false;
		for(int i = 0; i<n; i++)
			if(grid[i][j] != '.')
			{
				int type = grid[i][j] - '0';
				if(i%2 == 0 && (type == 1 || type == 4) || i%2 == 1 && (type == 2 || type == 3)) typea = true;
				else typeb = true;
				empty = false;
			}
		if(empty) pow = (pow*2)%mod;
		if(typea && typeb) good = false;
	}
	if(good) out.println(pow);
	else out.println(0);
	out.close();
}

public static class input {
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	static void init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	static String next() throws IOException {
		while (!tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(reader.readLine());
		return tokenizer.nextToken();
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
}
}


//package codeforces;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(System.out);
    StringTokenizer stringTokenizer;

    C() throws IOException {
//        reader = new BufferedReader(new FileReader("input.txt"));
//        writer = new PrintWriter(new FileWriter("bridges.out"));
    }

    String next() throws IOException {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            stringTokenizer = new StringTokenizer(reader.readLine());
        }
        return stringTokenizer.nextToken();
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    final int MOD = 1000 * 1000 + 3;

    int sum(int a, int b) {
        a += b;
        return a >= MOD ? a - MOD : a;
    }

    int product(int a, int b) {
        return (int) (1l * a * b % MOD);
    }

    int pow(int x, int k) {
        int result = 1;
        while (k > 0) {
            if (k % 2 == 1) {
                result = product(result, x);
            }
            x = product(x, x);
            k /= 2;
        }
        return result;
    }

    int inv(int x) {
        return pow(x, MOD - 2);
    }

    void solve() throws IOException {
        final int UP = 1 << 1;
        final int DOWN = 0;
        final int LEFT = 1;
        final int RIGHT = 0;
        int[] masks = {UP | LEFT, DOWN | LEFT, DOWN | RIGHT, UP | RIGHT};
        int rows = nextInt(), columns = nextInt();
        int[] leftRight = new int[rows], upDown = new int[columns];
        for(int row = 0; row < rows; row++) {
            char[] a = next().toCharArray();
            for(int column = 0; column < columns; column++) {
                if(a[column] != '.') {
                    int mask = masks[a[column] - '1'];
                    leftRight[row] |= 1 << ((mask & 1) ^ (column & 1));
                    upDown[column] |= 1 << ((mask >> 1) ^ (row & 1));
                }
            }
        }
        int ans = 1;
        for (int[] array : new int[][]{leftRight, upDown}) {
            for (int i : array) {
                if(i == 0) ans = product(ans, 2);
                else if(i == 3) ans = 0;
            }
        }
        writer.println(ans);
        writer.close();
    }

    public static void main(String[] args) throws IOException {
        new C().solve();
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;

    static final int MOD = 1000003;

    static boolean isLeft(char ch) {
        return ch == '1' || ch == '2';
    }

    static boolean isUp(char ch) {
        return ch == '1' || ch == '4';
    }

    public static void solve() throws IOException {
        int n = nextInt(), m = nextInt();
        char[][] grid = new char[n][];
        for(int i = 0; i < n; i++)
            grid[i] = nextToken().toCharArray();
        for(int i = 0; i < n; i++) {
            int firstPosition = -1;
            for(int j = 0; j < m; j++)
                if(grid[i][j] != '.') {
                    firstPosition = j;
                    break;
                }
            if(firstPosition == -1) continue;
            boolean current = isLeft(grid[i][firstPosition]);
            for(int pos = firstPosition + 1; pos < m; pos++) {
                if(grid[i][pos] == '.') continue;
                if(isLeft(grid[i][pos]) == current && (pos - firstPosition) % 2 == 0)
                    continue;
                if(isLeft(grid[i][pos]) == !current && (pos - firstPosition) % 2 == 1)
                    continue;
                out.println(0);
                return;
            }
            for(int pos = firstPosition - 1; pos >= 0; pos--) {
                if(grid[i][pos] == '.') continue;
                if(isLeft(grid[i][pos]) == current && (-pos + firstPosition) % 2 == 0)
                    continue;
                if(isLeft(grid[i][pos]) == !current && (-pos + firstPosition) % 2 == 1)
                    continue;
                out.println(0);
                return;
            }
        }
        for(int j = 0; j < m; j++) {
            int firstPosition = -1;
            for(int i = 0; i < n; i++)
                if(grid[i][j] != '.') {
                    firstPosition = i;
                    break;
                }
            if(firstPosition == -1) continue;
            boolean current = isUp(grid[firstPosition][j]);
            for(int pos = firstPosition + 1; pos < n; pos++) {
                if(grid[pos][j] == '.') continue;
                if(isUp(grid[pos][j]) == current && (pos - firstPosition) % 2 == 0)
                    continue;
                if(isUp(grid[pos][j]) == !current && (pos - firstPosition) % 2 == 1)
                    continue;
                out.println(0);
                return;
            }
            for(int pos = firstPosition - 1; pos >= 0; pos--) {
                if(grid[pos][j] == '.') continue;
                if(isUp(grid[pos][j]) == current && (-pos + firstPosition) % 2 == 0)
                    continue;
                if(isUp(grid[pos][j]) == !current && (-pos + firstPosition) % 2 == 1)
                    continue;
                out.println(0);
                return;
            }
        }
        int emptyRows = 0, emptyCols = 0;
        for(int i = 0; i < n; i++) {
            boolean isEmpty = true;
            for(int j = 0; j < m; j++)
                if(grid[i][j] != '.') {
                    isEmpty = false;
                    break;
                }
            if(isEmpty) ++emptyRows;
        }
        for(int j = 0; j < m; j++) {
            boolean isEmpty = true;
            for(int i = 0; i < n; i++)
                if(grid[i][j] != '.') {
                    isEmpty = false;
                    break;
                }
            if(isEmpty) ++emptyCols;
        }
        out.println(pow2(emptyRows + emptyCols));
    }

    static int pow2(int exp) {
        int res = 1, base = 2;
        while(exp > 0) {
            if(exp % 2 == 1)
                res = (int)(res * (long) base % MOD);
            base = (int)(base * (long) base % MOD);
            exp >>= 1;
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        InputStream input = System.in;
        OutputStream output = System.out;
        br = new BufferedReader(new InputStreamReader(input));
        out = new PrintWriter(output);
        solve();
        out.close();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public static String nextToken() throws IOException {
        while(st == null || !st.hasMoreTokens()) {
            String line = br.readLine();
            if(line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <set>
#define MAXN 100010
#define INF 1000000007
#define MP(x,y) make_pair(x,y)
#define FI first
#define SE second
#define EPS 1e-8
using namespace std;
char **ma;
int ty[2][4]={{1,1,0,0},{1,0,0,1}};
int pow_mod(long long a,int p,int mod)
{
    long long ret=1;
    while(p)
    {
        if(p&1) ret=ret*a%mod;
        a=a*a%mod,p>>=1;
    }
    return ret;
}
int main()
{
    int n,m,cnt;
    while(scanf("%d%d",&n,&m)==2)
    {
        cnt=0;
        bool flag=1;
        ma=new char *[n];
        for(int i=0;i<n;++i)
        {
            int pre=-1;
            bool tmp=1;
            ma[i]=new char [m+1];
            scanf("%s",ma[i]);
            for(int j=0;j<m;++j)
                if(ma[i][j]>='0')
                {
                    ma[i][j]-='1';
                    if(pre!=-1)
                        flag&=((j-pre)&1)==(ty[0][ma[i][j]]^ty[0][ma[i][pre]]);
                    pre=j;
                    tmp=0;
                }
            if(tmp)    ++cnt;
        }
        for(int i=0;i<m&&flag;++i)
        {
            int pre=-1;
            bool tmp=1;
            for(int j=0;j<n;++j)
                if(ma[j][i]<=3)
                {
                    if(pre!=-1)
                        flag&=((j-pre)&1)==(ty[1][ma[j][i]]^ty[1][ma[pre][i]]);
                    pre=j;
                    tmp=0;
                }
            if(tmp)    ++cnt;
        }
        printf("%d\n",flag?pow_mod(2,cnt,1000003):0);
        for(int i=0;i<n;++i)    delete ma[i];
        delete ma;
    }
    return 0;
}//hello


#include <bits/stdc++.h>
typedef long long LL;
#define rep(i,n) for(int i = 0;i < n;i ++)

const int N = 500050;
const int mod = 1e6 + 3;
std::string field[N];
char buf[N];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	rep(i, n) {
		scanf("%s", buf);
		field[i] = buf;
	}
	int ways = 1;
	rep(i, n) {
		bool can = true, f = false;;
		rep(j, m) if(field[i][j] != '.') {
			f = true;
		}
		if(!f) {
			ways = ways * 2 % mod;
			continue;
		}
		bool vis[4] = {false};
		for(int j = 0; j < m; j += 2) {
			if(field[i][j] == '.')	continue;
			vis[field[i][j] - '1'] = true;
		}
		if((vis[0]||vis[1]) && (vis[2]||vis[3]))
			ways = 0;
		rep(_, 4)	vis[_] = false;

		for(int j = 1; j < m; j += 2) {
			if(field[i][j] == '.')	continue;
			vis[field[i][j] - '1'] = true;
		}
		if((vis[0]||vis[1]) && (vis[2]||vis[3]))
			ways = 0;
		for(int j = 1; j < m; j ++) {
			if(field[i][j-1] != '.' && field[i][j] != '.') {
				if((field[i][j] == '1' || field[i][j] == '2') && (field[i][j-1] == '1' || field[i][j-1] == '2'))
					ways = 0;
				if((field[i][j] == '3' || field[i][j] == '4') && (field[i][j-1] == '3' || field[i][j-1] == '4'))
					ways = 0;
			}
		}
	}

	rep(j, m) {
		bool can = true, f = false;;
		rep(i, n) if(field[i][j] != '.') {
			f = true;
		}
		if(!f) {
			ways = ways * 2 % mod;
			continue;
		}
		bool vis[4] = {false};
		for(int i = 0; i < n; i += 2) {
			if(field[i][j] == '.')	continue;
			vis[field[i][j] - '1'] = true;
		}
		if((vis[0]||vis[3]) && (vis[1]||vis[2]))
			ways = 0;
		rep(_, 4)	vis[_] = false;

		for(int i = 1; i < n; i += 2) {
			if(field[i][j] == '.')	continue;
			vis[field[i][j] - '1'] = true;
		}
		if((vis[0]||vis[3]) && (vis[1]||vis[2]))
			ways = 0;
		for(int i = 1; i < n; i ++) {
			if(field[i][j] != '.' && field[i-1][j] != '.') {
				if((field[i][j] == '1' || field[i][j] == '4') && (field[i-1][j] == '1' || field[i-1][j] == '4'))
					ways = 0;
				if((field[i][j] == '3' || field[i][j] == '2') && (field[i-1][j] == '3' || field[i-1][j] == '2'))
					ways = 0;
			}
		}
	}

	printf("%d\n", ways);
	return 0;
}


#include <bits/stdc++.h>
typedef long long LL;
#define rep(i,n) for(int i = 0;i < n;i ++)

const int N = 500050;
const int mod = 1e6 + 3;
std::string field[N];
char buf[N];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	rep(i, n) {
		scanf("%s", buf);
		field[i] = buf;
	}
	int ways = 1;
	rep(i, n) {
		int s = 0;
		rep(j, m) if(field[i][j] != '.') {
			s |= 1<<((field[i][j]=='1'||field[i][j]=='2')^(j&1));
		}
		if(s == 3)	ways = 0;
		if(s == 0)	ways = ways*2 % mod;
	}
	rep(j, m) {
		int s = 0;
		rep(i, n) if(field[i][j] != '.') {
			s |= 1<<((field[i][j]=='3'||field[i][j]=='2')^(i&1));
		}
		if(s == 3)	ways = 0;
		if(s == 0)	ways = ways*2 % mod;
	}
	printf("%d\n", ways);
	return 0;
}


#include <cstdio>
#include <cassert>
#include <fstream>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <vector>
#include <list>
#include <map>
#include <ctime>
#include <iomanip>
#define LSOne(S) (S & (-S))
#define Max(u , v) (u < v) ? v : u
#define Min(u , v) (u < v) ? u : v
#define REP(i, l, r) for(int i = (l); i <= (r); i++)
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a) memset(a, 0, sizeof a)
#define add push_back

using namespace std;

typedef long long LL;
const LL mod = 1000000007;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main (){
    int n,m;
    scanf("%d %d", &n, &m);
    string S;
    set<int> H[n];
    set<int> V[m];
    FOR(i,n) {
        cin >> S;
        FOR(j,m) if (S[j] != '.') {
            int t = S[j] - '0';
            int h = (t <= 2);
            int v = (t ==  1 || t == 4);
            H[i].insert((h + j) % 2);
            V[j].insert((v + i) % 2);
        }
    }
    bool good = true;
    int cnt = m+n;
    FOR(i,n) {
        if (H[i].size() > 1)
            good = 0;
        else if (H[i].size())
            --cnt;
    }

    FOR(j,m) {
        if (V[j].size() > 1)
            good = 0;
        else if (V[j].size())
            --cnt;
    }

    if (good) {
        int ans = 1;
        FOR(i,cnt) {
            ans += ans;
            ans %= 1000003;
        }
        cout << ans << endl;
    }
    else
        cout << 0 << endl;

    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#define mod 1000003
#define ll __int64
using namespace std;
const int N=500005;

char str[N];
int n,m;
int row[N][2],col[N][2];

int main()
{
//	std::ios::sync_with_stdio(false);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf(" %s",str+1);
		for(int j=1;j<=m;j++)
		{
			if(str[j]!='.')
			{
				if(str[j]=='1'){
					if(j%2) row[i][1]=1;
					else row[i][0]=1;
					if(i%2) col[j][1]=1;
					else col[j][0]=1;
				}
				if(str[j]=='2'){
					if(j%2) row[i][1]=1;
					else row[i][0]=1;
					if(i%2) col[j][0]=1;
					else col[j][1]=1;
				}
				if(str[j]=='3'){
					if(j%2) row[i][0]=1;
					else row[i][1]=1;
					if(i%2) col[j][0]=1;
					else col[j][1]=1;
				}
				if(str[j]=='4'){
					if(j%2) row[i][0]=1;
					else row[i][1]=1;
					if(i%2) col[j][1]=1;
					else col[j][0]=1;
				}
			}
		}
	}
	int ans=1;
	for(int i=1;i<=n;i++){
		ans*=(2-row[i][0]-row[i][1]);
		ans%=mod;
	}
	for(int i=1;i<=m;i++){
		ans*=(2-col[i][0]-col[i][1]);
		ans%=mod;
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int maxx = 5e5 + 20, mod = 1e6 + 3;

ll r[maxx], c[maxx], ans = 1ll;

int main()
{
	bool b = true;
	ll n, m, rp, cp;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			char cc;
			cin >> cc;
			if (cc == '.')
				continue;
			if (cc == '1')
                        {
				if (j % 2 ? rp = 1 : rp = 2);
				if (i % 2 ? cp = 1 : cp = 2);
			}
			if (cc == '2')
                        {
				if (j % 2 ? rp = 1 : rp = 2);
                                if (i % 2 ? cp = 2 : cp = 1);
                        }
			if (cc == '3')
                        {
				if (j % 2 ? rp = 2 : rp = 1);
                                if (i % 2 ? cp = 2 : cp = 1);
                        }

			if (cc == '4')
                        {
				if (j % 2 ? rp = 2 : rp = 1);
                                if (i % 2 ? cp = 1 : cp = 2);
                        }
			if (r[i] + rp == 3 || c[j] + cp == 3)
                                b = false;
                        r[i] = rp, c[j] = cp;
//			cout << i << " " << j << " | " << rp << " " << cp << endl;
		}
	}
	if (!b)
	{
		cout << 0 << endl;
		return 0;
	}
	for(int i = 0; i < n; i++)
	{
		if (!r[i])
			ans = (ans * 2) % mod;
	}
	for(int i = 0; i < m; i++)
	{
		if (!c[i])
			ans = (ans * 2) % mod;
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define FOR(i,s,e) for (int i=(s); i<(e); i++)
#define FOE(i,s,e) for (int i=(s); i<=(e); i++)
#define FOD(i,s,e) for (int i=(s); i>=(e); i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); puts("");}
#define LL long long
#define ULL unsigned long long
#define eps 1e-9
#define pi acos(-1.0)
#define df(s) {freopen("s.in", "r", stdin); freopen("s.out", "w", stdout);}
LL max(LL a,LL b){if (a>b){return a;} else {return b;}}
LL min(LL a,LL b){if (a<b){return a;} else {return b;}}

int r[600001], c[600001];
int res = 0;

int n, m;
LL ret = 1;
#define mod 1000003

void calc(){
        FOE(i, 1, n){
                int cnt = 0;
                if (r[i] & 1) cnt++; if (r[i] & 2) cnt++;
                r[i] = cnt;
        }
        FOE(i, 1, m){
                int cnt = 0;
                if (c[i] & 1) cnt++; if (c[i] & 2) cnt++;
                c[i] = cnt;
        }
}

int f(int a, int b){
        printf("REV %d %d\n", a, b);
        if (b % 2) return a; else return 3 - a;
}

int main(){
        cin >> n >> m;
        FOE(i, 1, n) r[i] = 3;
        FOE(i, 1, m) c[i] = 3;

        FOE(i, 1, n){
                string x; cin >> x;
                FOE(j, 1, m) if (x[j - 1] != '.'){
//                      printf("j = %d\n", j);
                        if (x[j - 1] == '1'){
                                r[i] -= (r[i] & f(1, j));
                                c[j] -= (c[j] & f(1, i));
                        } else if (x[j - 1] == '2'){
                                r[i] -= (r[i] & f(1, j));
                                c[j] -= (c[j] & f(2, i));
                        } else if (x[j - 1] == '3'){
                                r[i] -= (r[i] & f(2, j));
                                c[j] -= (c[j] & f(2, i));
                        } else {
                                r[i] -= (r[i] & f(2, j));
                                c[j] -= (c[j] & f(1, i));
                        }
                }
        }

//      printf("%d\n", r[1]);

        calc();
        FOE(i, 1, n) ret = (ret * r[i]) % mod;
        FOE(i, 1, m) ret = (ret * c[i]) % mod;
        cout << ret << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define FOR(i,s,e) for (int i=(s); i<(e); i++)
#define FOE(i,s,e) for (int i=(s); i<=(e); i++)
#define FOD(i,s,e) for (int i=(s); i>=(e); i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); puts("");}
#define LL long long
#define ULL unsigned long long
#define eps 1e-9
#define pi acos(-1.0)
#define df(s) {freopen("s.in", "r", stdin); freopen("s.out", "w", stdout);}
LL max(LL a,LL b){if (a>b){return a;} else {return b;}}
LL min(LL a,LL b){if (a<b){return a;} else {return b;}}

int r[600001], c[600001];
int res = 0;

int n, m;
LL ret = 1;
#define mod 1000003

void calc(){
        FOE(i, 1, n){
                int cnt = 0;
                if (r[i] & 1) cnt++; if (r[i] & 2) cnt++;
                r[i] = cnt;
        }
        FOE(i, 1, m){
                int cnt = 0;
                if (c[i] & 1) cnt++; if (c[i] & 2) cnt++;
                c[i] = cnt;
        }
}

int f(int a, int b){
        if (b % 2) return a; else return 3 - a;
}

int main(){
        cin >> n >> m;
        FOE(i, 1, n) r[i] = 3;
        FOE(i, 1, m) c[i] = 3;

        FOE(i, 1, n){
                string x; cin >> x;
                FOE(j, 1, m) if (x[j - 1] != '.'){
//                      printf("j = %d\n", j);
                        if (x[j - 1] == '1'){
                                r[i] -= (r[i] & f(1, j));
                                c[j] -= (c[j] & f(1, i));
                        } else if (x[j - 1] == '2'){
                                r[i] -= (r[i] & f(1, j));
                                c[j] -= (c[j] & f(2, i));
                        } else if (x[j - 1] == '3'){
                                r[i] -= (r[i] & f(2, j));
                                c[j] -= (c[j] & f(2, i));
                        } else {
                                r[i] -= (r[i] & f(2, j));
                                c[j] -= (c[j] & f(1, i));
                        }
                }
        }

//      printf("%d\n", r[1]);

        calc();
        FOE(i, 1, n) ret = (ret * r[i]) % mod;
        FOE(i, 1, m) ret = (ret * c[i]) % mod;
        cout << ret << endl;

    return 0;
}


#include<stdio.h>
#define FZ(i,n) for(int i=0;i<n;++i)
#define RI(x) scanf("%d",&x)
constexpr int N = 514000;
#include<vector>
using namespace std;
constexpr int mod = 1000003;
int cal(int n,int m,const char*mp){
	int ans = 1;
	FZ(i,n){
		int v[2]{-1,-1};
		bool flag = true;
		FZ(k,2)for(int j = k;j<m;j+=2){
			if(v[k]==-1&&mp[i*m+j]!=71){
				v[k] = mp[i*m+j];
			}
			if(mp[i*m+j]!=71&&mp[i*m+j]!=v[k]){
				flag = false;
			}
		}
		ans*= flag;
		ans*= (v[0]!=v[1]||v[0]==-1);
		ans*= 1+(v[0]==-1&&v[1]==-1);
		ans%=mod;
	}
	return ans;
}
int n,m;
char mp[N],mq[N];
void sol(){
	FZ(i,n){
		scanf("%s",mp+i*m);
		FZ(j,m){
			if(mp[i*m+j]=='.'){
				mq[j*m+i] = mp[i*m+j] = 71;
			}else{
				mp[i*m+j]-= '1';
				if(mp[i*m+j]==1||mp[i*m+j]==3)
					mq[j*m+i] = mp[i*m+j]^2;
				else
					mq[j*m+i] = mp[i*m+j];
				mp[i*m+j]/=2;
				mq[j*m+i]/=2;
			}
		}
	}
	int t1 = cal(n,m,mp);
	int t2 = cal(m,n,mq);
	//printf("%d %d\n",t1,t2);
	printf("%d\n",int(t1*(long long int)t2%mod));
}
int main(){
	while(RI(n)!=EOF&&RI(m)!=EOF)sol();
	return 0;
}


#include<stdio.h>
#define FZ(i,n) for(int i=0;i<n;++i)
#define RI(x) scanf("%d",&x)
constexpr int N = 514000;
#include<vector>
using namespace std;
constexpr int mod = 1000003;
int cal(int n,int m,const char*mp){
	int ans = 1;
	FZ(i,n){
		int v[2]{-1,-1};
		bool flag = true;
		FZ(k,2)for(int j = k;j<m;j+=2)if(mp[i*m+j]!=71){
			if(v[k]==-1){
				v[k] = mp[i*m+j];
			}else if(mp[i*m+j]!=v[k]){
				flag = false;
			}
		}
		ans*= flag;
		ans*= (v[0]!=v[1]||v[0]==-1);
		ans*= 1+(v[0]==-1&&v[1]==-1);
		ans%=mod;
	}
	return ans;
}
int n,m;
char mp[N],mq[N];
void sol(){
	FZ(i,n){
		scanf("%s",mp+i*m);
		FZ(j,m){
			if(mp[i*m+j]=='.'){
				mq[j*n+i] = mp[i*m+j] = 71;
			}else{
				mp[i*m+j]-= '1';
				if(mp[i*m+j]==1||mp[i*m+j]==3)
					mq[j*n+i] = mp[i*m+j]^2;
				else
					mq[j*n+i] = mp[i*m+j];
				mp[i*m+j]/=2;
				mq[j*n+i]/=2;
			}
		}
	}
	int t1 = cal(n,m,mp);
	int t2 = cal(m,n,mq);
	//printf("%d %d\n",t1,t2);
	printf("%d\n",int(t1*(long long int)t2%mod));
}
int main(){
	while(RI(n)!=EOF&&RI(m)!=EOF)sol();
	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;

const int mx = 5e5 + 7;
const int md = 1e6 + 3;
int n, m;
char a[mx], s[mx];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d%d",&m,&n);
	for(int i = 0; i <= m; ++i){
	 	scanf("%s",&s);
	 	for(int j = 0; j < n; ++j){
	 		if (s[j] != '.') a[i * n + j] = s[j];
		}
	}
	int ans = 1;
	for(int i = 0; i < m; ++i){
		int d = 3;
		for(int j = 0; j < n; ++j){
			if (a[i * n + j] == '1' || a[i * n + j] == '2') d &= j % 2 + 1;
			if (a[i * n + j] == '4' || a[i * n + j] == '3') d &= 2 - j % 2;
		}
		if (d == 3) ans = (ans * 2) % md;
		if (d == 0) ans = 0;
	}
	if (m == 707) cout<<"hi";
	for(int j = 0; j < n; ++j){
		int d = 3;
		for(int i = 0; i < m; ++i){
			if (a[i * n + j] == '1' || a[i * n + j] == '4') d &= i % 2 + 1;
			if (a[i * n + j] == '3' || a[i * n + j] == '2') d &= 2 - i % 2;
		}
		if (d == 3) ans = (ans * 2) % md;
		if (d == 0) ans = 0;
	}	if (m == 707) cout<<"hi";
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;

const int mx = 5e5 + 7;
const int md = 1e6 + 3;
int n, m;
char a[mx], s[mx];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d%d",&m,&n);
	for(int i = 0; i <= m; ++i){
	 	scanf("%s",&s);
	 	for(int j = 0; j < n; ++j){
	 		if (s[j] != '.') a[i * n + j] = s[j];
		}
	}
	int ans = 1;
	for(int i = 0; i < m; ++i){
		int d = 3;
		for(int j = 0; j < n; ++j){
			if (a[i * n + j] == '1' || a[i * n + j] == '2') d &= j % 2 + 1;
			if (a[i * n + j] == '4' || a[i * n + j] == '3') d &= 2 - j % 2;
		}
		if (d == 3) ans = (ans * 2) % md;
		if (d == 0) ans = 0;
	}
	for(int j = 0; j < n; ++j){
		int d = 3;
		for(int i = 0; i < m; ++i){
			if (a[i * n + j] == '1' || a[i * n + j] == '4') d &= i % 2 + 1;
			if (a[i * n + j] == '3' || a[i * n + j] == '2') d &= 2 - i % 2;
		}
		if (d == 3) ans = (ans * 2) % md;
		if (d == 0) ans = 0;
	}
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;

const int mx = 5e5 + 7;
const int md = 1e6 + 3;
int n, m;
char a[mx], s[mx];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d%d",&m,&n);
	for(int i = 0; i < m; ++i){
	 	scanf("%s",&s);
	 	for(int j = 0; j < n; ++j){
	 		if (s[j] != '.') a[i * n + j] = s[j];
		}
	}
	int ans = 1;
	for(int i = 0; i < m; ++i){
		int d = 3;
		for(int j = 0; j < n; ++j){
			if (a[i * n + j] == '1' || a[i * n + j] == '2') d &= j % 2 + 1;
			if (a[i * n + j] == '4' || a[i * n + j] == '3') d &= 2 - j % 2;
		}
		if (d == 3) ans = (ans * 2) % md;
		if (d == 0) ans = 0;
	}
	for(int j = 0; j < n; ++j){
		int d = 3;
		for(int i = 0; i < m; ++i){
			if (a[i * n + j] == '1' || a[i * n + j] == '4') d &= i % 2 + 1;
			if (a[i * n + j] == '3' || a[i * n + j] == '2') d &= 2 - i % 2;
		}
		if (d == 3) ans = (ans * 2) % md;
		if (d == 0) ans = 0;
	}
	printf("%d",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <queue>
#include <math.h>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#include <list>
#include <ctype.h>
#include <cassert>
#include <stack>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <functional>
#include <ctime>
#include <limits>
#include <tuple>
#include <complex>

using namespace std;

#define snd second
#define fst first
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define left _left
#define right _right

const ld pi = acos(-1.0l);

template<typename T>
T abs(T x) {
    return x > 0 ? x : -x;
}

template<typename T>
T sqr(T x) {
    return x * x;
}

template<typename T>
void chmin(T &x, T y) {
    x = min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
    x = max(x, y);
}

template<typename U, typename V>
ostream &operator<<(ostream &s, const pair<U, V> &x) {
    s << "(" << x.fst << ", " << x.snd << ")";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const vector<U> &x) {
    s << "[";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "]";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const set<U> &x) {
    s << "{";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "}";
    return s;
}

template<int sz>
ostream operator<<(ostream &s, const bitset<sz> &x) {
    for (int i = 0; i < sz; i++) {
        s << x[i];
    }
    return s;
}

//-----------------------------------------------------------------------------

const int maxn = 5e5 + 5;
const int mod = 1000003;
char s[maxn];

int main() {

    srand(time(NULL));

    retry:

#ifdef LOCAL
    //gen();
    //cerr << 1 << endl;
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

#else
    //freopen("hovels.in", "r", stdin);
    //freopen("hovels.out", "w", stdout);
#endif

    int n, m;
    scanf("%d %d\n", &n, &m);

    vector<vector<int>> a(n, vector<int>(m, -1));
    for (int i = 0; i < n; i++) {
        scanf("%s\n", s);
        for (int j = 0; j < m; j++) {
            if (isdigit(s[j])) {
                a[i][j] = s[j] - '1';
            }
        }
    }

    auto die = []() {
        cout << 0 << endl;
        exit(0);
    };

    int ans = 1;
    for (int i = 0; i < n; i++) {
        int p = -1;
        for (int j = 0; j < m; j++) {
            if (a[i][j] != -1) {
                p = j ^ bool(a[i][j] & 2);
                break;
            }
        }

        if (p == -1) {
            ans = ans * 2 % mod;
            continue;
        }

        for (int j = 0; j < m; j++) {
            if (a[i][j] != -1 && (j ^ bool(a[i][j] & 2)) != p) {
                die();
            }
        }
    }

    auto vert = [](int x) {
        return x == 0 || x == 3;
    };

    for (int i = 0; i < m; i++) {
        int p = -1;
        for (int j = 0; j < n; j++) {
            if (a[j][i] != -1) {
                p = j ^ vert(a[j][i]);
                break;
            }
        }

        if (p == -1) {
            ans = ans * 2 % mod;
            continue;
        }

        for (int j = 0; j < n; j++) {
            if (a[j][i] != -1 && (j ^ vert(a[j][i])) != p) {
                die();
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <queue>
#include <math.h>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#include <list>
#include <ctype.h>
#include <cassert>
#include <stack>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <functional>
#include <ctime>
#include <limits>
#include <tuple>
#include <complex>

using namespace std;

#define snd second
#define fst first
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define left _left
#define right _right

const ld pi = acos(-1.0l);

template<typename T>
T abs(T x) {
    return x > 0 ? x : -x;
}

template<typename T>
T sqr(T x) {
    return x * x;
}

template<typename T>
void chmin(T &x, T y) {
    x = min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
    x = max(x, y);
}

template<typename U, typename V>
ostream &operator<<(ostream &s, const pair<U, V> &x) {
    s << "(" << x.fst << ", " << x.snd << ")";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const vector<U> &x) {
    s << "[";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "]";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const set<U> &x) {
    s << "{";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "}";
    return s;
}

template<int sz>
ostream operator<<(ostream &s, const bitset<sz> &x) {
    for (int i = 0; i < sz; i++) {
        s << x[i];
    }
    return s;
}

//-----------------------------------------------------------------------------

const int maxn = 5e5 + 5;
const int mod = 1000003;
char s[maxn];

int main() {

    srand(time(NULL));

    retry:

#ifdef LOCAL
    //gen();
    //cerr << 1 << endl;
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

#else
    //freopen("hovels.in", "r", stdin);
    //freopen("hovels.out", "w", stdout);
#endif

    int n, m;
    scanf("%d %d\n", &n, &m);

    vector<vector<int>> a(n, vector<int>(m, -1));
    for (int i = 0; i < n; i++) {
        scanf("%s\n", s);
        for (int j = 0; j < m; j++) {
            if (isdigit(s[j])) {
                a[i][j] = s[j] - '1';
            }
        }
    }

    auto die = []() {
        cout << 0 << endl;
        exit(0);
    };

    int ans = 1;
    for (int i = 0; i < n; i++) {
        int p = -1;
        for (int j = 0; j < m; j++) {
            if (a[i][j] != -1) {
                p = (j & 1) ^ bool(a[i][j] & 2);
                break;
            }
        }

        if (p == -1) {
            ans = ans * 2 % mod;
            continue;
        }

        for (int j = 0; j < m; j++) {
            if (a[i][j] != -1 && ((j & 1) ^ bool(a[i][j] & 2)) != p) {
                die();
            }
        }
    }

    auto vert = [](int x) {
        return x == 0 || x == 3;
    };

    for (int i = 0; i < m; i++) {
        int p = -1;
        for (int j = 0; j < n; j++) {
            if (a[j][i] != -1) {
                p = (j & 1) ^ vert(a[j][i]);
                break;
            }
        }

        if (p == -1) {
            ans = ans * 2 % mod;
            continue;
        }

        for (int j = 0; j < n; j++) {
            if (a[j][i] != -1 && ((j & 1) ^ vert(a[j][i])) != p) {
                die();
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define mp make_pair
#define ll long long
#define pb push_back

using namespace std;

string a[510000];

int x1[510000];
int x2[510000];

bool z = true;

int mod(int x1, int x2) {
    if (x1 == 0) return x2+1;
    if (x1 != x2+1) z = false;
    return x1;
}

int main() {

    cin.sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;

    for (int i = 0; i <= n; i++)
        x1[i] = 0;
    for (int i = 0; i <= m; i++)
        x2[i] = 0;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
        if (a[i][j] == '1' || a[i][j] == '2') {

            x1[i] = mod(x1[i],j%2);
        }
        if (a[i][j] == '3' || a[i][j] == '4') {

            x1[i] = mod(x1[i],(j+1)%2);
        }
        if (a[i][j] == '1' || a[i][j] == '4') {

            x2[j] = mod(x2[j],i%2);
        }
        if (a[i][j] == '3' || a[i][j] == '2') {

            x2[j] = mod(x2[j],(i+1)%2);
        }
   }

    int ans = 1;
    if (!z) ans = 0;
    for (int i = 0; i < n; i++)
        if (x1[i] == 0) ans = (ans*2)%1000003;
//        cout << x1[i] << " ";
//    cout << "\n";
    for (int i = 0; i < m; i++ )
//        cout << x2[i] << " ";
        if (x2[i] == 0) ans = (ans*2)%1000003;
    cout << ans;

    return 0;
}


#include<stdlib.h>
#include<time.h>
#include<assert.h>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long UL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define sz(x) ((int)(x.size()))
#define sqr(x) ((x)*(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const LL INF = 1e9 + 7;
const UL SEED = 1e6 + 7;
const int N = 5e5 + 7;
const int MOD = 1e6 + 3;
const double Pi = acos(-1.);
const double EPS = 1e-8;
const int h[] = { 0, 0, 1, 1 };
const int v[] = { 0, 1, 1, 0 };
int n, m;
struct Node {
	int sz, a[N];
	void insert(int x) {
		a[sz++] = x;
	}
	int v(int i, int j) {
		return a[i * m + j];
	}
} nd;
LL kpow(LL a, LL b) {
	LL ret = 1;
	while (b) {
		if (b & 1)
			ret = ret * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return ret;
}
void inc(int &x, int y) {
	x += y;
	x -= (x >= MOD ? MOD : 0);
}
char getChar() {
	char ch = getchar();
	while (!(ch == '.' || ('1' <= ch && ch <= '4')))
		ch = getchar();
	return ch;
}
int solve() {
	int ans = 1;
	for (int i = 0; i < n; ++i) {
		int j = 0, p;
		while (j < m && !nd.v(i, j))
			++j;
		if (j == m) {
			inc(ans, ans);
		} else {
			p = h[nd.v(i, j)];
			while (j + 1 < m) {
				++j;
				if (nd.v(i, j) && (p ^ 1) != h[nd.v(i, j)])
					return 0;
				p ^= 1;
			}
		}
	}
	for (int j = 0; j < m; ++j) {
		int i = 0, p;
		while (i < n && !nd.v(i, j))
			++i;
		if (i == n) {
			inc(ans, ans);
		} else {
			p = v[nd.v(i, j)];
			while (i + 1 < n) {
				++i;
				if (nd.v(i, j) && (p ^ 1) != v[nd.v(i, j)])
					return 0;
				p ^= 1;
			}
		}
	}
	return ans;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			char ch = getChar();
			if (ch == '.') {
				nd.insert(0);
			} else {
				nd.insert(ch - '0');
			}
		}
	}
	printf("%d", solve());
	return 0;
}


#include<stdlib.h>
#include<time.h>
#include<assert.h>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long UL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define sz(x) ((int)(x.size()))
#define sqr(x) ((x)*(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const LL INF = 1e9 + 7;
const int N = 1e6 + 7;
const int MOD = 1e6 + 3;
const double Pi = acos(-1.);
const double EPS = 1e-8;
const int h[] = { 0, 0, 1, 1 };
const int v[] = { 0, 1, 1, 0 };
int n, m, a[N];
void inc(int &x, int y) {
	x += y;
	x -= (x >= MOD ? MOD : 0);
}
char getChar() {
	char ch = getchar();
	while (!(ch == '.' || ('1' <= ch && ch <= '4')))
		ch = getchar();
	return ch;
}
int solve() {
	int ans = 1;
	for (int i = 0; i < n; ++i) {
		int j = 0, p;
		while (j < m && !a[i * m + j])
			++j;
		if (j == m) {
			inc(ans, ans);
		} else {
			p = h[a[i * m + j]];
			while (j + 1 < m) {
				++j;
				if (a[i * m + j] && (p ^ 1) != h[a[i * m + j]])
					return 0;
				p ^= 1;
			}
		}
	}
	for (int j = 0; j < m; ++j) {
		int i = 0, p;
		while (i < n && !a[i * m + j])
			++i;
		if (i == n) {
			inc(ans, ans);
		} else {
			p = v[a[i * m + j]];
			while (i + 1 < n) {
				++i;
				if (a[i * m + j] && (p ^ 1) != v[a[i * m + j]])
					return 0;
				p ^= 1;
			}
		}
	}
	return ans;
}
int main() {
	scanf("%d%d", &n, &m);
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j, ++cnt) {
			char ch = getChar();
			if (ch == '.') {
				a[cnt] = 0;
			} else {
				a[cnt] = ch - '0';
			}
		}
	}
	printf("%d", solve());
	return 0;
}


#include<stdlib.h>
#include<time.h>
#include<assert.h>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long UL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define sz(x) ((int)(x.size()))
#define sqr(x) ((x)*(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const LL INF = 1e9 + 7;
const UL SEED = 1e6 + 7;
const int N = 5e5 + 7;
const int MOD = 1e6 + 3;
const double Pi = acos(-1.);
const double EPS = 1e-8;
const int h[] = { 0, 0, 1, 1 };
const int v[] = { 0, 1, 1, 0 };
int n, m;
vi a[N];
LL kpow(LL a, LL b) {
	LL ret = 1;
	while (b) {
		if (b & 1)
			ret = ret * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return ret;
}
void inc(int &x, int y) {
	x += y;
	x -= (x >= MOD ? MOD : 0);
}
char getChar() {
	char ch = getchar();
	while (!(ch == '.' || ('1' <= ch && ch <= '4')))
		ch = getchar();
	return ch;
}
int solve() {
	int ans = 1;
	for (int i = 0; i < n; ++i) {
		int j = 0, p;
		while (j < m && !a[i][j])
			++j;
		if (j == m) {
			inc(ans, ans);
		} else {
			p = h[a[i][j]];
			while (j + 1 < m) {
				++j;
				if (a[i][j] && (p ^ 1) != h[a[i][j]])
					return 0;
				p ^= 1;
			}
		}
	}
	for (int j = 0; j < m; ++j) {
		int i = 0, p;
		while (i < n && !a[i][j])
			++i;
		if (i == n) {
			inc(ans, ans);
		} else {
			p = v[a[i][j]];
			while (i + 1 < n) {
				++i;
				if (a[i][j] && (p ^ 1) != v[a[i][j]])
					return 0;
				p ^= 1;
			}
		}
	}
	return ans;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j) {
			char ch = getChar();
			if (ch == '.') {
				a[i].pb(0);
			} else {
				a[i].pb(ch - '0');
			}
		}
	printf("%d", solve());
	return 0;
}


#include<stdlib.h>
#include<time.h>
#include<assert.h>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long UL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define sz(x) ((int)(x.size()))
#define sqr(x) ((x)*(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const LL INF = 1e9 + 7;
const int N = 1e6 + 7;
const int MOD = 1e6 + 3;
const double Pi = acos(-1.);
const double EPS = 1e-8;
const int h[] = { 0, 0, 0, 1, 1 };
const int v[] = { 0, 0, 1, 1, 0 };
int n, m, a[N];
void inc(int &x, int y) {
	x += y;
	x -= (x >= MOD ? MOD : 0);
}
char getChar() {
	char ch = getchar();
	while (!(ch == '.' || ('1' <= ch && ch <= '4')))
		ch = getchar();
	return ch;
}
int solve() {
	int ans = 1;
	for (int i = 0; i < n; ++i) {
		int j = 0, p;
		while (j < m && !a[i * m + j])
			++j;
		if (j == m) {
			inc(ans, ans);
		} else {
			p = h[a[i * m + j]];
			while (j + 1 < m) {
				++j;
				if (a[i * m + j] && (p ^ 1) != h[a[i * m + j]])
					return 0;
				p ^= 1;
			}
		}
	}
	for (int j = 0; j < m; ++j) {
		int i = 0, p;
		while (i < n && !a[i * m + j])
			++i;
		if (i == n) {
			inc(ans, ans);
		} else {
			p = v[a[i * m + j]];
			while (i + 1 < n) {
				++i;
				if (a[i * m + j] && (p ^ 1) != v[a[i * m + j]])
					return 0;
				p ^= 1;
			}
		}
	}
	return ans;
}
int main() {
	scanf("%d%d", &n, &m);
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			char ch = getChar();
			a[cnt++] = (ch == '.' ? 0 : ch - '0');
		}
	}
	printf("%d", solve());
	return 0;
}


#include<stdlib.h>
#include<time.h>
#include<assert.h>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long UL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define sz(x) ((int)(x.size()))
#define sqr(x) ((x)*(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const LL INF = 1e9 + 7;
const UL SEED = 1e6 + 7;
const int N = 5e5 + 7;
const int MOD = 1e6 + 3;
const double Pi = acos(-1.);
const double EPS = 1e-8;
const int h[] = { 0, 0, 1, 1 };
const int v[] = { 0, 1, 1, 0 };
int n, m;
vi a[N];
LL kpow(LL a, LL b) {
	LL ret = 1;
	while (b) {
		if (b & 1)
			ret = ret * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return ret;
}
void inc(int &x, int y) {
	x += y;
	x -= (x >= MOD ? MOD : 0);
}
char getChar() {
	char ch = getchar();
	while (!(ch == '.' || ('1' <= ch && ch <= '4')))
		ch = getchar();
	return ch;
}
int solve() {
	int ans = 1;
	for (int i = 0; i < n; ++i) {
		int j = 0, p;
		while (j < m && !a[i][j])
			++j;
		if (j == m) {
			inc(ans, ans);
		} else {
			p = h[a[i][j]];
			while (j + 1 < m) {
				++j;
				if (a[i][j] && (p ^ 1) != h[a[i][j]])
					return 0;
				p ^= 1;
			}
		}
	}
	for (int j = 0; j < m; ++j) {
		int i = 0, p;
		while (i < n && !a[i][j])
			++i;
		if (i == n) {
			inc(ans, ans);
		} else {
			p = v[a[i][j]];
			while (i + 1 < n) {
				++i;
				if (a[i][j] && (p ^ 1) != v[a[i][j]])
					return 0;
				p ^= 1;
			}
		}
	}
	return ans;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) {
		a[i].clear();
		for (int j = 0; j < m; ++j) {
			char ch = getChar();
			if (ch == '.') {
				a[i].pb(0);
			} else {
				a[i].pb(ch - '0');
			}
		}
	}
	printf("%d", solve());
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <set>
#define MAXN 100010
#define INF 1000000007
#define MP(x,y) make_pair(x,y)
#define FI first
#define SE second
#define EPS 1e-8
using namespace std;
char **ma;
int ty[2][4]={{1,1,0,0},{1,0,0,1}};
int pow_mod(long long a,int p,int mod)
{
    long long ret=1;
    while(p)
    {
        if(p&1) ret=ret*a%mod;
        a=a*a%mod,p>>=1;
    }
    return ret;
}
int main()
{
    int n,m,cnt;
    while(scanf("%d%d",&n,&m)==2)
    {
        cnt=0;
        bool flag=1;
        ma=new char *[n];
        for(int i=0;i<n;++i)
        {
            int pre=-1;
            bool tmp=1;
            ma[i]=new char [m+1];
            scanf("%s",ma[i]);
            for(int j=0;j<m;++j)
                if(ma[i][j]>='0')
                {
                    ma[i][j]-='1';
                    if(pre!=-1)
                        flag&=((j-pre)&1)==(ty[0][ma[i][j]]^ty[0][ma[i][pre]]);
                    pre=j;
                    tmp=0;
                }
            if(tmp)    ++cnt;
        }
        for(int i=0;i<m&&flag;++i)
        {
            int pre=-1;
            bool tmp=1;
            for(int j=0;j<n;++j)
                if(ma[j][i]<=3)
                {
                    if(pre!=-1)
                        flag&=((j-pre)&1)==(ty[1][ma[j][i]]^ty[1][ma[pre][i]]);
                    pre=j;
                    tmp=0;
                }
            if(tmp)    ++cnt;
        }
        printf("%d\n",flag?pow_mod(2,cnt,1000003):0);
        for(int i=0;i<n;++i)    delete ma[i];
        delete ma;
    }
    return 0;
}


#include <bits/stdc++.h>

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

#define mod 1000003

int n, m, ans = 1;
char s[500005];

char eat(){
	char c;
	while(scanf("%c", &c)){
		if(c != ' ' && c != '\n') return c;
	}
}

vector<int> v;

int calc(){
	int sz = v.size();
	int ret = 0;
	FI(i, 1, 2){
		int cur = i;
		FI(j, 0, sz - 1){
			if(v[j] == cur) goto gg;
			cur = 3 - cur;
		}
		ret++;
		gg:;
	}
	return ret;
}

int main(){
	scanf("%d %d", &n, &m);
	FI(i, 1, n * m) s[i] = eat();
	FI(i, 1, n){
		v.clear();
		FI(j, 1, m){
			char x = s[(i - 1) * m + j];
			if(x == '.') v.push_back(0);
			else if(x == '1' || x == '2') v.push_back(2);
			else v.push_back(1);
		}
		ans = (ans * calc()) % mod;
	}
	FI(j, 1, m){
		v.clear();
		FI(i, 1, n){
			char x = s[(i - 1) * m + j];
			if(x == '.') v.push_back(0);
			else if(x == '1' || x == '4') v.push_back(2);
			else v.push_back(1);
		}
		ans = (ans * calc()) % mod;
	}
	printf("%d\n", ans);
	return 0;
}


//#pragma comment(linker, "/STACK:102400000,102400000")
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;

typedef long long ll;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define DE(val) cout<<#val<<": "<<val<<endl;

const int dx44[5] = { 0,-1,-1,1,1 };
const int dy44[5] = { 0,-1,1,-1,1 };

const int dx4[5] = { 0,-1,0,1,0 };
const int dy4[5] = { 0,0,1,0,-1 };
const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int maxn = 5e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1000003;
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes");}// exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No");}// exit(0); }
void one() { puts("-1"); exit(0); }

int n,m;
char val[maxn];
ll f[maxn][2],g[maxn][2];

void solve()
{
	sa(n),sa(m);
	repp(i,1,n)
	{
		scanf("%s",val+1);
		repp(j,1,m)
		{
			if(val[j]!='.')
			{
				if(val[j]=='1'||val[j]=='2')
				{
					f[i][j&1]=1;
				}
				else
				{
					f[i][!(j&1)]=1;
				}

				if(val[j]=='1'||val[j]=='4')
				{
					g[j][i&1]=1;
				}
				else
				{
					g[j][!(i&1)]=1;
				}
			}
		}
	}
	ll ans=1;
	repp(i,1,n)
	{
		ans=ans*(2-f[i][0]-f[i][1]);
		ans%=mod;
	}
	repp(i,1,m)
	{
		ans=ans*(2-g[i][0]-g[i][1]);
		ans%=mod;
	}
	cout<<ans<<endl;
}

int main()
{
	solve();
	// system("pause");
	return 0;
}


#include <iostream>

const long long MOD=1000003;

long long vbar[500005];
long long hbar[500005];

int main(){
  long long N,M;
  std::cin>>N>>M;
  for(long long i=0;i<N;i++){
    for(long long j=0;j<M;j++){
      while(true){
	char c=std::cin.get();
	switch(c){
	case '.':
	  break;
	case '1':
	  vbar[i]|=(1<<(j%2));
	  hbar[j]|=(1<<(i%2));
	  break;
	case '2':
	  vbar[i]|=(1<<(j%2));
	  hbar[j]|=(1<<((i+1)%2));
	  break;
	case '3':
	  vbar[i]|=(1<<((j+1)%2));
	  hbar[j]|=(1<<((i+1)%2));
	  break;
	case '4':
	  vbar[i]|=(1<<((j+1)%2));
	  hbar[j]|=(1<<(i%2));
	  break;
	default:
	  continue;
	}
	break;
      }
    }
  }
  long long ways=1;
  for(long long i=0;i<N;i++){
    switch(vbar[i]){
    case 0:
      ways*=2;
      break;
    case 1:
    case 2:
      break;
    case 3:
      ways=0;
      break;
    }
  }
  for(long long j=0;j<M;j++){
    switch(hbar[j]){
    case 0:
      ways*=2;
      break;
    case 1:
    case 2:
      break;
    case 3:
      ways=0;
      break;
    }
  }
  std::cout<<ways<<std::endl;
  return 0;
}


#include <iostream>

const long long MOD=1000003;

long long vbar[500005];
long long hbar[500005];

int main(){
  long long N,M;
  std::cin>>N>>M;
  for(long long i=0;i<N;i++){
    for(long long j=0;j<M;j++){
      while(true){
	char c=std::cin.get();
	switch(c){
	case '.':
	  break;
	case '1':
	  vbar[i]|=(1<<(j%2));
	  hbar[j]|=(1<<(i%2));
	  break;
	case '2':
	  vbar[i]|=(1<<((j+1)%2));
	  hbar[j]|=(1<<(i%2));
	  break;
	case '3':
	  vbar[i]|=(1<<((j+1)%2));
	  hbar[j]|=(1<<((i+1)%2));
	  break;
	case '4':
	  vbar[i]|=(1<<(j%2));
	  hbar[j]|=(1<<((i+1)%2));
	  break;
	default:
	  continue;
	}
	break;
      }
    }
  }
  long long ways=1;
  for(long long i=0;i<N;i++){
    switch(vbar[i]){
    case 0:
      ways*=2;
      break;
    case 1:
    case 2:
      break;
    case 3:
      ways=0;
      break;
    }
  }
  for(long long j=0;j<M;j++){
    switch(hbar[j]){
    case 0:
      ways*=2;
      break;
    case 1:
    case 2:
      break;
    case 3:
      ways=0;
      break;
    }
  }
  std::cout<<ways<<std::endl;
  return 0;
}


#include <iostream>

const long long MOD=1000003;

long long vbar[500005];
long long hbar[500005];

int main(){
  long long N,M;
  std::cin>>N>>M;
  for(long long i=0;i<N;i++){
    for(long long j=0;j<M;j++){
      while(true){
	char c=std::cin.get();
	switch(c){
	case '.':
	  break;
	case '1':
	  vbar[i]|=(1<<(j%2));
	  hbar[j]|=(1<<(i%2));
	  break;
	case '2':
	  vbar[i]|=(1<<(j%2));
	  hbar[j]|=(1<<((i+1)%2));
	  break;
	case '3':
	  vbar[i]|=(1<<((j+1)%2));
	  hbar[j]|=(1<<((i+1)%2));
	  break;
	case '4':
	  vbar[i]|=(1<<((j+1)%2));
	  hbar[j]|=(1<<(i%2));
	  break;
	default:
	  continue;
	}
	break;
      }
    }
  }
  long long ways=1;
  for(long long i=0;i<N;i++){
    switch(vbar[i]){
    case 0:
      ways*=2;
      ways%=MOD;
      break;
    case 1:
    case 2:
      break;
    case 3:
      ways=0;
      break;
    }
  }
  for(long long j=0;j<M;j++){
    switch(hbar[j]){
    case 0:
      ways*=2;
      ways%=MOD;
      break;
    case 1:
    case 2:
      break;
    case 3:
      ways=0;
      break;
    }
  }
  std::cout<<ways<<std::endl;
  return 0;
}


#include <iostream>

const int MOD=1000003;

int vbar[500005];
int hbar[500005];

int main(){
  int N,M;
  std::cin>>N>>M;
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      while(true){
	char c=std::cin.get();
	switch(c){
	case '.':
	  break;
	case '1':
	  vbar[i]|=(1<<(j%2));
	  hbar[j]|=(1<<(i%2));
	  break;
	case '2':
	  vbar[i]|=(1<<(j%2));
	  hbar[j]|=(1<<((i+1)%2));
	  break;
	case '3':
	  vbar[i]|=(1<<((j+1)%2));
	  hbar[j]|=(1<<((i+1)%2));
	  break;
	case '4':
	  vbar[i]|=(1<<((j+1)%2));
	  hbar[j]|=(1<<(i%2));
	  break;
	default:
	  continue;
	}
	break;
      }
    }
  }
  int ways=1;
  for(int i=0;i<N;i++){
    switch(vbar[i]){
    case 0:
      ways*=2;
      break;
    case 1:
    case 2:
      break;
    case 3:
      ways=0;
      break;
    }
  }
  for(int j=0;j<M;j++){
    switch(hbar[j]){
    case 0:
      ways*=2;
      break;
    case 1:
    case 2:
      break;
    case 3:
      ways=0;
      break;
    }
  }
  std::cout<<ways<<std::endl;
  return 0;
}


#include <bits/stdc++.h>

#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-8;
const ld EPSLD = 1e-18;
const ll MOD = 1e9+7;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }

const int MAX_N = 500010;

int n, m;

char cs[MAX_N];
string s[MAX_N];

int cnt;
int mo = 1000003;

int main(){

  scanf( "%d %d" , &n , &m );
  REP( i , n ){
    scanf( "%s" , cs );
    s[i] = cs;
  }

  REP( i , n ){
    int cur = -1;
    REP( j , m ){
      if( s[i][j] == '.' ) continue;
      int x = ( s[i][j] - '1' ) / 2;
      if( cur == -1 ) cur = x + j;
      else if( cur % 2 != ( x + j ) % 2 ){
	cur = -INF;
	break;
      }
    }
    if( cur == -1 ) cnt++;
    if( cur == -INF ){
      printf( "0\n" );
      return 0;
    }
  }

  REP( j , m ){
    int cur = -1;
    REP( i , n ){
      if( s[i][j] == '.' ) continue;
      int x = ( s[i][j] == '1' || s[i][j] == '4' ) ? 0 : 1;
      if( cur == -1 ) cur = x + i;
      else if( cur % 2 != ( x + i ) % 2 ){
	cur = -INF;
	break;
      }
    }
    if( cur == -1 ) cnt++;
    if( cur == -INF ){
      printf( "0\n" );
      return 0;
    }
  }

  int ans = 1;
  REP( i , cnt ) ans = ( ans * 2 ) % mo;

  printf( "%d\n" , ans );

  return 0;
}


#include<stdio.h>
#include<assert.h>
#include<string.h>
#include<algorithm>
using namespace std;

typedef long long lld;

const int MOD= 1000003;
const int K=5*1e5;
const int M=708;

char maze[K+10];
bool fnm;

bool changNum(char ch[],int m){
    int i,x=0;
    for(i=0;i<m;i++){
        if(ch[i]!='.'){
            ch[i]--;
            ch[i]-='0';
            x++;
        }
    }
    return x==0;
}

bool checkX(int x,int m,int &s){
    int i,j,d=-1;
    s=1;
    j=x*m;
    for(i=0;i<m;i++){
        if(d>-1)d=(d+2)%4;
        char c=maze[j+i];

        if(c!='.'){
            s=0;
            if(d==-1){
                d=c;
                if(d%2==0)d=(d+1)%4;
            }
            else{
                if(d!=c&&(d!=(c+1)%4))return false;
            }
        }
    }
    return true;
}

bool checkY(int y,int n,int &s){
    int i,j,d=-1;
    s=1;
    j=y;
    for(i=0;i<n;i++){
        if(d>-1)d=(d+2)%4;
        char c;

        c=maze[j+i*n];

        if(c!='.'){
            s=0;
            if(d==-1){
                d=c;
                if(d%2)d=(d+1)%4;
            }
            else{
                if(d!=c&&(d!=(c+1)%4))return false;
            }
        }
    }
    return true;

}

int pow_mod(int x,int n){
    int sum=1;
    while(n){
        if(n&1)sum=sum*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return sum;
}

void solve(){
    int n,m;
    int i,j,x,y;
    //printf("%d",'.');
    while(scanf("%d%d",&n,&m)!=EOF){
        assert(1<=n&&n<=K);
        assert(1<=m&&m<=K);
        assert(1<=m*n&&m*n<=K);
        x=0;
        for(i=0;i<n;i++){
            scanf("%s",maze+i*m);
        }
        assert(strlen(maze)==n*m);
        changNum(maze,n*m);
        printf("%d\n",strlen(maze));
        //puts(maze);
        y=0;
        x=0;
        for(i=0;i<n;i++){
            if(!checkX(i,m,j)){
                x=1;
            }
            y+=j;
            if(x)break;
        }

        for(i=0;i<m;i++){
            if(!checkY(i,n,j)){
                x=1;
            }
            y+=j;
            if(x)break;
        }
        if(x){puts("0");}
        else{
            printf("%d\n",pow_mod(2,y));
        }
    }
}

int main(){
    solve();
    return 0;
}


#include<stdio.h>
#include<assert.h>
#include<string.h>
#include<algorithm>
using namespace std;

typedef long long lld;

const int MOD= 1000003;
const int K=5*1e5;
const int M=708;

char maze[K+10];
bool fnm;

bool changNum(char ch[],int m){
    int i,x=0;
    for(i=0;i<m;i++){
        if(ch[i]!='.'){
            ch[i]--;
            //ch[i]-='0';
            x++;
        }
    }
    return x==0;
}

bool checkX(int x,int m,int &s){
    int i,j,d=-1;
    s=1;
    j=x*m;
    for(i=0;i<m;i++){
        if(d>-1)d=(d+2)%4;
        char c=maze[j+i];

        if(c!='.'){
            s=0;
            if(d==-1){
                d=c-'0';
                if(d%2==0)d=(d+1)%4;
            }
            else{
                if(d!=c&&(d!=(c+1)%4))return false;
            }
        }
    }
    return true;
}

bool checkY(int y,int n,int &s){
    int i,j,d=-1;
    s=1;
    j=y;
    for(i=0;i<n;i++){
        if(d>-1)d=(d+2)%4;
        char c;

        c=maze[j+i*n];
        putchar(c);
        if(c!='.'){
            s=0;
            if(d==-1){
                d=c;
                if(d%2)d=(d+1)%4;
            }
            else{
                if(d!=c&&(d!=(c+1)%4))return false;
            }
        }
    }
    return true;

}

lld pow_mod(lld x,int n){
    lld sum=1;
    while(n){
        if(n&1)sum=sum*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return sum;
}

void solve(){
    int n,m;
    int i,j,x,y;
//printf("%d\n",pow_mod(2,1500));
    while(scanf("%d%d",&n,&m)!=EOF){
        assert(1<=n&&n<=K);
        assert(1<=m&&m<=K);
        assert(1<=m*n&&m*n<=K);
        x=0;
        for(i=0;i<n;i++){
            scanf("%s",maze+i*m);
        }
        assert(strlen(maze)==n*m);
        changNum(maze,n*m);
        //if(n==500)
        printf("%d\n",strlen(maze));
        puts(maze);
        y=0;
        x=0;
        for(i=0;i<n;i++){
            if(!checkX(i,m,j)){
                x=1;
            }
            y+=j;
            if(x)break;
        }
        printf("%d\n",y);

        for(i=0;i<m;i++){
            if(!checkY(i,n,j)){
                x=1;
            }
            y+=j;
            if(j)printf("%d\n",i);
            if(x)break;
        }
        //printf("%d\n",y);
        if(x){puts("0");}
        else{
            printf("%d\n",pow_mod(2,y));
        }
    }
}

int main(){
    solve();
    return 0;
}


#include<stdio.h>
#include<assert.h>
#include<string.h>
#include<algorithm>
using namespace std;

typedef long long lld;

const int MOD= 1000003;
const int K=5*1e5;
const int M=708;

char maze[K+10];
bool fnm;

bool changNum(char ch[],int m){
    int i,x=0;
    for(i=0;i<m;i++){
        if(ch[i]!='.'){
            ch[i]--;
            ch[i]-='0';
            x++;
        }
    }
    return x==0;
}

bool checkX(int x,int m,int &s){
    int i,j,d=-1;
    s=1;
    j=x*m;
    for(i=0;i<m;i++){
        if(d>-1)d=(d+2)%4;
        char c=maze[j+i];

        if(c!='.'){
            s=0;
            if(d==-1){
                d=c;
                if(d%2==0)d=(d+1)%4;
            }
            else{
                if(d!=c&&(d!=(c+1)%4))return false;
            }
        }
    }
    return true;
}

bool checkY(int y,int n,int &s){
    int i,j,d=-1;
    s=1;
    j=y;
    for(i=0;i<n;i++){
        if(d>-1)d=(d+2)%4;
        char c;

        c=maze[j+i*n];

        if(c!='.'){
            s=0;
            if(d==-1){
                d=c;
                if(d%2)d=(d+1)%4;
            }
            else{
                if(d!=c&&(d!=(c+1)%4))return false;
            }
        }
    }
    return true;

}

int pow_mod(int x,int n){
    int sum=1;
    while(n){
        if(n&1)sum=sum*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return sum;
}

void solve(){
    int n,m;
    int i,j,x,y;
    //printf("%d",'.');
    while(scanf("%d%d",&n,&m)!=EOF){
        assert(1<=n&&n<=K);
        assert(1<=m&&m<=K);
        assert(1<=m*n&&m*n<=K);
        x=0;
        for(i=0;i<n;i++){
            scanf("%s",maze+i*m);
        }
        assert(strlen(maze)==n*m);
        changNum(maze,n*m);
        if(n==500)
        printf("%d\n",strlen(maze));
        //puts(maze);
        y=0;
        x=0;
        for(i=0;i<n;i++){
            if(!checkX(i,m,j)){
                x=1;
            }
            y+=j;
            if(x)break;
        }

        for(i=0;i<m;i++){
            if(!checkY(i,n,j)){
                x=1;
            }
            y+=j;
            if(x)break;
        }
        if(x){puts("0");}
        else{
            printf("%d\n",pow_mod(2,y));
        }
    }
}

int main(){
    solve();
    return 0;
}


#include<stdio.h>
#include<assert.h>
#include<string.h>
#include<algorithm>
using namespace std;

typedef long long lld;

const int MOD= 1000003;
const int K=5*1e5;
const int M=750;

char maze1[K+100][M];
char maze2[M][K+100];
bool fnm;

bool changNum(char ch[],int m){
    int i,x=0;
    for(i=0;i<m;i++){
        if(ch[i]!='.'){
            ch[i]--;
            ch[i]-='0';
            x++;
        }
    }
    return x==0;
}

bool checkX(int x,int m,int &s){
    int i,j,d=-1;
    s=1;
    for(i=0;i<m;i++){
        if(d>-1)d=(d+2)%4;
        char c;
        if(fnm){
            c=maze1[x][i];
        }
        else{
            c=maze2[x][i];
        }
        if(c!='.'){
            s=0;
            if(d==-1){
                d=c;
                if(d%2==0)d=(d+1)%4;
            }
            else{
                if(d!=c&&(d!=(c+1)%4))return false;
            }
        }
    }
    return true;
}

bool checkY(int y,int n,int &s){
    int i,j,d=-1;
    s=1;
    for(i=0;i<n;i++){
        if(d>-1)d=(d+2)%4;
        char c;
        if(fnm){
            c=maze1[i][y];
        }
        else{
            c=maze2[i][y];
        }
        if(c!='.'){
            s=0;
            if(d==-1){
                d=c;
                if(d%2)d=(d+1)%4;
            }
            else{
                if(d!=c&&(d!=(c+1)%4))return false;
            }
        }
    }
    return true;

}

int pow_mod(int x,int n){
    int sum=1;
    while(n){
        if(n&1)sum=sum*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return sum;
}

void solve(){
    int n,m;
    int i,j,x,y;
    //printf("%d",'.');
    while(scanf("%d%d",&n,&m)!=EOF){
        assert(1<=n&&n<=K);
        assert(1<=m&&m<=K);
        assert(1<=m*n&&m*n<=K);
        x=0;
        fnm=n>m;
        for(i=0;i<n;i++){
            if(fnm){
                scanf("%s",maze1[i]);
                assert(strlen(maze1[i])==m);
                changNum(maze1[i],m);
            }
            else{
                scanf("%s",maze2[i]);
                assert(strlen(maze2[i])==m);
                changNum(maze2[i],m);
            }
        }
        y=0;
        x=0;
        for(i=0;i<n;i++){
            if(!checkX(i,m,j)){
                x=1;
            }
            y+=j;
            if(x)break;
        }

        for(i=0;i<m;i++){
            if(!checkY(i,n,j)){
                x=1;
            }
            y+=j;
            if(x)break;
        }
        if(x){puts("0");}
        else{
            printf("%d\n",pow_mod(2,y));
        }
    }
}

int main(){
    solve();
    return 0;
}