#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
int main()
{
	int i,j,k;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	vector<char>v;
	if(abs(c-d)>1)
		printf("-1\n");
	else
	{
		if(c==d)
		{
			int x=a-c;
			int y=b-c;
			if(x<0||y<0||x+y<1)
			{
				printf("-1\n");
				return 0;
			}
			if(a>=b)
			{
				while(x--)
					printf("4");
				while(c!=1)
				{
					printf("74");
					c--;
				}
				while(y--)
					printf("7");
				printf("74");
			}
			else if(x==0)
			{
				printf("7");
				y--;
				while(c--)
					printf("47");
				while(y--)
					printf("7");
			}
			else
			{
				while(x!=1)
				{
					x--;
					printf("4");
				}
				while(c--)
					printf("47");
				while(y--)
					printf("7");
				printf("4");
			}
		}
		else if(c>d)
		{
			int x=a-c;
			int y=b-c;
			if(x<0||y<0)
			{
				printf("-1\n");
				return 0;
			}
			while(x--)
				printf("4");
			while(c--)
				printf("47");
			while(y--)
				printf("7");
		}
		else
		{
			int x=a-d;
			int y=b-d;
			if(x<0||y<0)
			{
				printf("-1\n");
				return 0;
			}
			if(d==2)
			{
				printf("7");
				while(x--)
					printf("4");
				printf("47");
				while(y--)
					printf("7");
				printf("4");
			}
			else
			{
				printf("74");
				while(x--)
					printf("4");
				d--;
				while(d!=1)
				{
					d--;
					printf("74");
				}
				while(y--)
					printf("7");
				printf("74");
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
int main()
{
	int i,j,k;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	vector<char>v;
	if(abs(c-d)>1)
		printf("-1\n");
	else
	{
		if(c==d)
		{
			int x=a-c;
			int y=b-c;
			if(x<0||y<0||x+y<1)
			{
				printf("-1\n");
				return 0;
			}
			if(a>=b)
			{
				while(x--)
					printf("4");
				while(c!=1)
				{
					printf("74");
					c--;
				}
				while(y--)
					printf("7");
				printf("74");
			}
			else
			{
				printf("7");
				y--;
				while(x--)
					printf("4");
				printf("47");
				c--;
				while(c--)
					printf("47");
				while(y--)
					printf("7");
			}
		}
		else if(c>d)
		{
			int x=a-c;
			int y=b-c;
			if(x<0||y<0)
			{
				printf("-1\n");
				return 0;
			}
			while(x--)
				printf("4");
			while(c--)
				printf("47");
			while(y--)
				printf("7");
		}
		else
		{
			int x=a-d;
			int y=b-d;
			if(x<0||y<0)
			{
				printf("-1\n");
				return 0;
			}
			if(d==2)
			{
				printf("7");
				while(x--)
					printf("4");
				printf("47");
				while(y--)
					printf("7");
				printf("4");
			}
			else
			{
				printf("74");
				while(x--)
					printf("4");
				d--;
				while(d!=1)
				{
					d--;
					printf("74");
				}
				while(y--)
					printf("7");
				printf("74");
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int a1,a2,a3,a4,type=0;
	cin>>a1>>a2>>a3>>a4;
	a4=a4-a3+1,a2-=a3,a1-=a3;
	if(a4==2) a1--,a2--,type=3;
	else  if(a4==1){ if(a1) a1--,type=1; else a2--,type=2; }
	if(a1<0 || a2<0 || a4>2 || a4<0) return cout<<-1<<endl,0;
	if(type==3) cout<<'7';
	for(int i=0;i<a1;i++) cout<<'4'; for(int i=0;i<a3;i++) cout<<"47"; for(int i=0;i<a2;i++) cout<<'7';
	if(type==1 || type==3) cout<<'4';
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int a1,a2,a3,a4,type=0;
	cin>>a1>>a2>>a3>>a4;
	a4=a4-a3+1,a2-=a3,a1-=a3;
	if(a4==2) a1--,a2--,type=3;
	else  if(a4==1){ if(a1) a1--,type=1; else a2--,type=2; }
	if(a1<0 || a2<0 || a4>2 || a4<0) return cout<<-1<<endl,0;
	if(type==3 || type==2) cout<<'7';
	for(int i=0;i<a1;i++) cout<<'4'; for(int i=0;i<a3;i++) cout<<"47"; for(int i=0;i<a2;i++) cout<<'7';
	if(type==1 || type==3) cout<<'4';
}


/*
 ID: jskswyq1
 PROG: twofive
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <string.h>
#include <string>
#include <vector>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
int a1,a2,a3,a4;
string s;

void check() {
    if (a1 < 0 || a2 < 0) {
        cout << -1 << endl;
        exit(0);
    }
}

void con1(string str, int t) {
    while (t) {
        s += str;
        t--;
    }
}

void con2(string str, int t) {
    while (t) {
        s = str+s;
        t--;
    }
}

int main() {
    cin >> a1 >> a2 >> a3 >> a4;
    if (a3 - a4 == 1) {
        a1 -= a3;
        a2 -= a3;
        check();
        con1("47", a3);
        con2("4",a1);
        con1("7", a2);
        cout << s << endl;
        return 0;
    } else if (a4 - a3 == 1) {
        a1 -= a4;
        a2 -= a4;
        check();
        con1("74", a4);
        s = s.substr(1);
        con2("4",a1);
        s = "7"+s;
        s = s.substr(0,s.length()-1);
        con1("7", a2);
        s += "4";
        cout << s << endl;
        return 0;
    } else if (a3 == a4) {
        if (a1 >= a3+1) {
            a1 -= a3+1;
            a2 -= a3;
            check();
            con1("47", a3);
            s += "4";
            con2("4",a1);
            s = s.substr(0,s.length()-1);
            con1("7",a2);
            s += "4";
            cout << s << endl;
            return 0;
        } else {
            a2 -= a3+1;
            a1 -= a3;
            check();
            con1("74", a3);
            con1("7", a2);
            s = s.substr(1);
            con2("4",a1);
            s += "7";
            cout << s << endl;
        }
    } else {
        cout << -1 << endl;
    }
}


/*
 ID: jskswyq1
 PROG: twofive
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <string.h>
#include <string>
#include <vector>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
int a1,a2,a3,a4;
char s[3000020];
int start = 1000000;
int finish = 1000000;

void check() {
    if (a1 < 0 || a2 < 0) {
        cout << -1 << endl;
        exit(0);
    }
}

void con1(string str, int t) {
    while (t) {
        for (int i = 0; i < str.length(); i++) {
            s[finish++] = str[i];
        }
        t--;
    }
}

void con2(string str, int t) {
    while (t) {
        for (int i = 0; i < str.length(); i++) {
            s[--start] = str[i];
        }
        t--;
    }
}

int main() {
    cin >> a1 >> a2 >> a3 >> a4;
    if (a3 - a4 == 1) {
        a1 -= a3;
        a2 -= a3;
        check();
        con1("47", a3);
        con2("4",a1);
        con1("7", a2);
        cout << s+start << endl;
        return 0;
    } else if (a4 - a3 == 1) {
        a1 -= a4;
        a2 -= a4;
        check();
        con1("74", a4);
        start++;
        con2("4",a1);
        s[--start] = '7';
        finish--;
        con1("7", a2);
        s[finish++] = '4';
        cout << s+start << endl;
        return 0;
    } else if (a3 == a4) {
        if (a1 >= a3+1) {
            a1 -= a3+1;
            a2 -= a3;
            check();
            con1("47", a3);
            s[finish++] = '4';
            con2("4",a1);
            finish--;
            con1("7",a2);
            s[finish++] = '4';
            cout << s+start << endl;
            return 0;
        } else {
            a2 -= a3+1;
            a1 -= a3;
            check();
            con1("74", a3);
            con1("7", a2);
            s[finish++] = '7';
            cout << s+start << endl;
        }
    } else {
        cout << -1 << endl;
    }
}


/*
 ID: jskswyq1
 PROG: twofive
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <string.h>
#include <string>
#include <vector>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
int a1,a2,a3,a4;
char s[2000020];
int start = 1000000;
int finish = 1000000;

void check() {
    if (a1 < 0 || a2 < 0) {
        cout << -1 << endl;
        exit(0);
    }
}

void con1(string str, int t) {
    while (t) {
        for (int i = 0; i < str.length(); i++) {
            s[finish++] = str[i];
        }
        t--;
    }
}

void con2(string str, int t) {
    while (t) {
        for (int i = 0; i < str.length(); i++) {
            s[--start] = str[i];
        }
        t--;
    }
}

int main() {
    cin >> a1 >> a2 >> a3 >> a4;
    if (a3 - a4 == 1) {
        a1 -= a3;
        a2 -= a3;
        check();
        con1("47", a3);
        con2("4",a1);
        con1("7", a2);
        cout << s+start << endl;
        return 0;
    } else if (a4 - a3 == 1) {
        a1 -= a4;
        a2 -= a4;
        check();
        con1("74", a4);
        start++;
        con2("4",a1);
        s[--start] = '7';
        finish--;
        con1("7", a2);
        s[finish++] = '4';
        cout << s+start << endl;
        return 0;
    } else if (a3 == a4) {
        if (a1 >= a3+1) {
            a1 -= a3+1;
            a2 -= a3;
            check();
            con1("47", a3);
            s[finish++] = '4';
            con2("4",a1);
            finish--;
            con1("7",a2);
            s[finish++] = '4';
            cout << s+start << endl;
            return 0;
        } else {
            a2 -= a3+1;
            a1 -= a3;
            check();
            con1("74", a3);
            con1("7", a2);
            s[finish++] = '7';
            cout << s+start << endl;
        }
    } else {
        cout << -1 << endl;
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <string>
#include <memory.h>
#include <bitset>

#define sci(a) scanf("%d", &a)
#define scii(a, b) scanf("%d%d", &a, &b)
#define sciii(a, b, c) scanf("%d%d%d", &a, &b, &c)

#define scid(a) int a; sci(a)
#define sciid(a, b) int a, b; scii(a, b)
#define sciiid(a, b, c) int a, b, c; sciii(a, b, c)

#define rea(a, n) for (int i = 0; i < n; i++) sci(a[i])

#define init_cin ios_base::sync_with_stdio(false); cin.tie(0);

typedef long long lint;
typedef long double ldouble;

using namespace std;

int main() {
    sciid(a1, a2);
    sciid(a3, a4);
    char c4 = '4';
    char c7 = '7';
    if (a1 <= a2) {
        swap(a1, a2);
        swap(a3, a4);
        swap(c4, c7);
    }
    if (abs(a3 - a4) > 1) {
        cout << -1;
        return 0;
    }

    if (a3 == 0 && a4 == 0 && a1 > 0 && a2 > 0) {
        cout << -1;
        return 0;
    }

    string ans = "";
    if (a3 > a4) {
        for (int i = 0; i < a3; i++) {
            ans += c4;
            ans += c7;
            a1--;
            a2--;
        }
    } else if (a4 > a3) {
        for (int i = 0; i < a4; i++) {
            ans += c7;
            ans += c4;
            a1--;
            a2--;
        }
    } else {
        ans += c7;
        a2--;
        for (int i = 0; i < a4; i++) {
            ans += c4;
            ans += c7;
            a1--;
            a2--;
        }
    }

    if (a1 < 0 || a2 < 0) {
        cout << -1;
        return 0;
    }

    int i4 = -1, i7 = -1;
    if (c4 < c7) {
        for (int i = 0; i < ans.size(); i++) {
            if (i4 == -1 && ans[i] == c4) {
                i4 = i;
            }
            if (ans[i] == c7) {
                i7 = i;
            }
        }
    } else {
        for (int i = 0; i < ans.size(); i++) {
            if (i7 == -1 && ans[i] == c7) {
                i7 = i;
            }
            if (ans[i] == c4) {
                i4 = i;
            }
        }
    }

    for (int i = 0; i < ans.size(); i++) {
        char c = ans[i];
        cout << c;
        while (i4 == i && a1 > 0) {
            cout << c4;
            a1--;
        }
        while (i7 == i && a2 > 0) {
            cout << c7;
            a2--;
        }
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <string>
#include <memory.h>
#include <bitset>

#define sci(a) scanf("%d", &a)
#define scii(a, b) scanf("%d%d", &a, &b)
#define sciii(a, b, c) scanf("%d%d%d", &a, &b, &c)

#define scid(a) int a; sci(a)
#define sciid(a, b) int a, b; scii(a, b)
#define sciiid(a, b, c) int a, b, c; sciii(a, b, c)

#define rea(a, n) for (int i = 0; i < n; i++) sci(a[i])

#define init_cin ios_base::sync_with_stdio(false); cin.tie(0);

typedef long long lint;
typedef long double ldouble;

using namespace std;

int main() {
    sciid(a1, a2);
    sciid(a3, a4);
    char c4 = '4';
    char c7 = '7';
    if (a1 <= a2) {
        swap(a1, a2);
        swap(a3, a4);
        swap(c4, c7);
    }
    if (abs(a3 - a4) > 1) {
        cout << -1;
        return 0;
    }

    if (a3 == 0 && a4 == 0 && a1 > 0 && a2 > 0) {
        cout << -1;
        return 0;
    }

    string ans = "";
    if (a3 > a4) {
        for (int i = 0; i < a3; i++) {
            ans += c4;
            ans += c7;
            a1--;
            a2--;
        }
    } else if (a4 > a3) {
        for (int i = 0; i < a4; i++) {
            ans += c7;
            ans += c4;
            a1--;
            a2--;
        }
    } else {
        ans += c7;
        a2--;
        for (int i = 0; i < a4; i++) {
            ans += c4;
            ans += c7;
            a1--;
            a2--;
        }
    }

    if (a1 < 0 || a2 < 0) {
        cout << -1;
        return 0;
    }

    for (char c : ans) {
        cout << c;
        while (c == c4 && a1 > 0) {
            cout << c4;
            a1--;
        }
        while (c == c7 && a2 > 0) {
            cout << c7;
            a2--;
        }
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <string>
#include <memory.h>
#include <bitset>

#define sci(a) scanf("%d", &a)
#define scii(a, b) scanf("%d%d", &a, &b)
#define sciii(a, b, c) scanf("%d%d%d", &a, &b, &c)

#define scid(a) int a; sci(a)
#define sciid(a, b) int a, b; scii(a, b)
#define sciiid(a, b, c) int a, b, c; sciii(a, b, c)

#define rea(a, n) for (int i = 0; i < n; i++) sci(a[i])

#define init_cin ios_base::sync_with_stdio(false); cin.tie(0);

typedef long long lint;
typedef long double ldouble;

using namespace std;

int main() {
    sciid(a1, a2);
    sciid(a3, a4);
    char c4 = '4';
    char c7 = '7';
    if (a1 > a2) {
        swap(a1, a2);
        swap(a3, a4);
        swap(c4, c7);
    }
    if (abs(a3 - a4) > 1) {
        cout << -1;
        return 0;
    }

    if (a3 == 0 && a4 == 0 && a1 > 0 && a2 > 0) {
        cout << -1;
        return 0;
    }

    string ans = "";
    if (a3 > a4) {
        for (int i = 0; i < a3; i++) {
            ans += c4;
            ans += c7;
            a1--;
            a2--;
        }
    } else if (a4 > a3) {
        for (int i = 0; i < a4; i++) {
            ans += c7;
            ans += c4;
            a1--;
            a2--;
        }
    } else {
        ans += c7;
        a2--;
        for (int i = 0; i < a4; i++) {
            ans += c4;
            ans += c7;
            a1--;
            a2--;
        }
    }

    if (a1 < 0 || a2 < 0) {
        cout << -1;
        return 0;
    }

    for (char c : ans) {
        cout << c;
        while (c == c4 && a1 > 0) {
            cout << c4;
            a1--;
        }
        while (c == c7 && a2 > 0) {
            cout << c7;
            a2--;
        }
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <string>
#include <memory.h>
#include <bitset>

#define sci(a) scanf("%d", &a)
#define scii(a, b) scanf("%d%d", &a, &b)
#define sciii(a, b, c) scanf("%d%d%d", &a, &b, &c)

#define scid(a) int a; sci(a)
#define sciid(a, b) int a, b; scii(a, b)
#define sciiid(a, b, c) int a, b, c; sciii(a, b, c)

#define rea(a, n) for (int i = 0; i < n; i++) sci(a[i])

#define init_cin ios_base::sync_with_stdio(false); cin.tie(0);

typedef long long lint;
typedef long double ldouble;

using namespace std;

string gen(string s, int c4, int c7, int c47, int c74, char last) {
    while (c47 > 0 || c74 > 0) {
        if (last == '4') {
            c47--;
            s += '7';
            c7--;
            last = '7';
        } else {
            c74--;
            s += '4';
            c4--;
            last = '4';
        }
    }
    if (c4 < 0 || c7 < 0 || c47 < 0 || c74 < 0) {
        return "";
    }
    string res = "";
    int i7 = -1;
    int i4 = -1;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '7') {
            i7 = i;
        }
        if (i4 == -1 && s[i] == '4') {
            i4 = i;
        }
    }

    for (int i = 0; i < s.size(); i++) {
        res += s[i];
        if (i == i4) {
            while (c4 > 0) {
                res += '4';
                c4--;
            }
        }
        if (i == i7) {
            while (c7 > 0) {
                res += '7';
                c7--;
            }
        }
    }

    if (c4 > 0 || c7 > 0) {
        return "";
    }
    return res;
}

int main() {
    sciid(a1, a2);
    sciid(a3, a4);
    if (abs(a3 - a4) > 1) {
        cout << -1;
        return 0;
    }

    if (a3 == 0 && a4 == 0 && a1 > 0 && a2 > 0) {
        cout << -1;
        return 0;
    }

    string s1 = gen("4", a1 - 1, a2, a3, a4, '4');
    string s2 = gen("7", a1, a2 - 1, a3, a4, '7');

    if (s1 == "" && s2 == "") {
        cout << -1;
    } else if (s1 == "") {
        cout << s2;
    } else if (s2 == "") {
        cout << s1;
    } else {
        cout << min(s1, s2);
    }

    return 0;
}


#include <cstdio>
#include <vector>
#include <cmath>
#include <cctype>
#define PT 520

using namespace std;

int n, m, nn, mm, fl;

vector <int> a[1000006];

int read()
{
    int s = 0, f = 1;
    char ch = getchar();
    while(!isdigit(ch)) {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(isdigit(ch)) {
        s = (s << 3) + (s << 1) + ch - '0';
        ch = getchar();
    }
    return s * f;
}

int main(){
	n = read(), m = read(), nn = read(), mm = read();
	if(nn > mm) swap(n, m), swap(nn, mm), fl = 1;
	if(nn == mm && n > m) swap(n, m), fl = 1;
	if(mm - nn > 1){
		printf("-1");
		return 0;
	}
	int k = nn + mm;
	a[1].push_back(1), --m;
	for(int i = 2; i <= k + 1; i++){
		if(i % 2 == 1){
			if(!nn || !m) {
				printf("-1\n");
				return 0;
			}
			a[i].push_back(1), --nn, --m;
		}
		else{
			if(!mm || !n){
				printf("-1\n");
				return 0;
			}
			a[i].push_back(2), --mm, --n; }
	}
	while(m--){
		a[1].push_back(1);
	}
	while(n--){
		a[2].push_back(2);
	}
	if(fl){
	for(int i = 1; i <= k + 1; ++i)
	for(int j = 0; j < a[i].size() ; ++j)
	if(a[i][0] == 1)
	printf("4");
	else printf("7");}
	else {
	for(int i = 1; i <= k + 1; ++i)
	for(int j = 0; j < a[i].size() ; ++j)
	if(a[i][0] == 1)
	printf("7");
	else printf("4");}
}


#include <cstdio>
#include <vector>
#include <cmath>
#include <cctype>
#define PT 520

using namespace std;

int n, m, nn, mm, fl, kn, km, knn, kmm;

vector <int> a[1000006];

int read()
{
    int s = 0, f = 1;
    char ch = getchar();
    while(!isdigit(ch)) {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(isdigit(ch)) {
        s = (s << 3) + (s << 1) + ch - '0';
        ch = getchar();
    }
    return s * f;
}

int main(){
	kn = n = read(), km = m = read(), knn = nn = read(),kmm = mm = read();
	if(nn >= mm) {
		int k = nn + mm;
		a[1].push_back(1), --n;
		for(int i = 2; i <= k + 1; i++){
			if(i % 2 == 1){
				if(!mm || !n) {
					goto there;
				}
				a[i].push_back(1), --mm, --n;
			}
			else{
				if(!nn || !m){
					goto there;
					return 0;
				}
				a[i].push_back(2), --nn, --m;
			}
//			printf("%d %d %d %d\n",n, m, nn, mm);
		}
		while(n--){
			a[1].push_back(1);
		}
		int w = k + 1;
		if(!(k % 2)) w--;
		while(m--){
			a[w].push_back(2);
		}
		for(int i = 1; i <= k + 1; ++i)
		for(int j = 0; j < a[i].size() ; ++j)
		if(a[i][j] == 1)
		printf("4");
		else printf("7");
	}
	else {
		there:;
		n = kn, m = km, mm = kmm, nn = knn;
		for(int i = 1; i <= mm + nn + 1; ++i)
		a[i].clear() ;
		int k = nn + mm;
		a[1].push_back(1), --m;
		for(int i = 2; i <= k + 1; i++){
			if(i % 2 == 1){
				if(!nn || !m) {
					printf("-1\n");
					return 0;
				}
				a[i].push_back(1), --nn, --m;
			}
			else{
				if(!mm || !n){
					printf("-1\n");
					return 0;
				}
				a[i].push_back(2), --mm, --n;
			}
//			printf("%d %d %d %d\n",n, m, nn, mm);
		}
		while(n--){
			a[2].push_back(2);
		}
		int w = k + 1;
		if(k % 2) w--;
		while(m--){
			a[w].push_back(1);
		}
		for(int i = 1; i <= k + 1; ++i)
		for(int j = 0; j < a[i].size() ; ++j)
		if(a[i][j] == 1)
		printf("7");
		else printf("4");
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <climits>
//#include <ext/hash_map>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for(int i = 0; i < int(n); ++i)
#define REPV(i, n) for (int i = (n) - 1; (int)i >= 0; --i)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)

#define FE(i,t) for (__typeof((t).begin())i=(t).begin();i!=(t).end();++i)
#define FEV(i,t) for (__typeof((t).rbegin())i=(t).rbegin();i!=(t).rend();++i)

#define two(x) (1LL << (x))
#define ALL(a) (a).begin(), (a).end()

#define pb push_back
#define ST first
#define ND second
#define MP(x,y) make_pair(x, y)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;

template<class T> void checkmin(T &a, T b){if (b<a)a=b;}
template<class T> void checkmax(T &a, T b){if (b>a)a=b;}
template<class T> void out(T t[], int n){REP(i, n)cout<<t[i]<<" "; cout<<endl;}
template<class T> void out(vector<T> t, int n=-1){for (int i=0; i<(n==-1?t.size():n); ++i) cout<<t[i]<<" "; cout<<endl;}
inline int count_bit(int n){return (n==0)?0:1+count_bit(n&(n-1));}
inline int low_bit(int n){return (n^n-1)&n;}
inline int ctz(int n){return (n==0?-1:ctz(n>>1)+1);}
int toInt(string s){int a; istringstream(s)>>a; return a;}
string toStr(int a){ostringstream os; os<<a; return os.str();}

const int mod=1e6+3;
int main(){
    int n,m;
    cin>>n>>m;
    getchar();

    vector<string> tb(n);
    int res=1;
    REP(i,n){
        cin>>tb[i];
        REP(j,m) if (tb[i][j]=='3') ++tb[i][j]; else if (tb[i][j]=='4') --tb[i][j];
        int fd=0;
        int prev=-1;
        REP(j,m){
            if (tb[i][j]!='.'){
                fd=1;
                int val=tb[i][j]-'1'&2;
                if (prev==-1) prev=val;
                else{
                    if (prev!=-1 && val==prev) res=0;
                    prev^=2;
                }
            }
        }
        if (!fd) res=res*2%mod;
    }
    REP(i,m){
        int fd=0;
        int prev=-1;
        REP(j,n){
            if (tb[j][i]!='.'){
                fd=1;
                int val=tb[j][i]-'1'&1;
                if (prev==-1) prev=val;
                else{
                    if (prev!=-1 && val==prev) res=0;
                    prev^=1;
                }
            }
        }
        if (!fd) res=res*2%mod;
    }

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


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <climits>
//#include <ext/hash_map>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for(int i = 0; i < int(n); ++i)
#define REPV(i, n) for (int i = (n) - 1; (int)i >= 0; --i)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)

#define FE(i,t) for (__typeof((t).begin())i=(t).begin();i!=(t).end();++i)
#define FEV(i,t) for (__typeof((t).rbegin())i=(t).rbegin();i!=(t).rend();++i)

#define two(x) (1LL << (x))
#define ALL(a) (a).begin(), (a).end()

#define pb push_back
#define ST first
#define ND second
#define MP(x,y) make_pair(x, y)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;

template<class T> void checkmin(T &a, T b){if (b<a)a=b;}
template<class T> void checkmax(T &a, T b){if (b>a)a=b;}
template<class T> void out(T t[], int n){REP(i, n)cout<<t[i]<<" "; cout<<endl;}
template<class T> void out(vector<T> t, int n=-1){for (int i=0; i<(n==-1?t.size():n); ++i) cout<<t[i]<<" "; cout<<endl;}
inline int count_bit(int n){return (n==0)?0:1+count_bit(n&(n-1));}
inline int low_bit(int n){return (n^n-1)&n;}
inline int ctz(int n){return (n==0?-1:ctz(n>>1)+1);}
int toInt(string s){int a; istringstream(s)>>a; return a;}
string toStr(int a){ostringstream os; os<<a; return os.str();}

const int mod=1e6+3;
int main(){
    int n,m;
    cin>>n>>m;
    getchar();

    vector<string> tb(n);
    int res=1;
    REP(i,n){
        cin>>tb[i];
        REP(j,m) if (tb[i][j]=='3') ++tb[i][j]; else if (tb[i][j]=='4') --tb[i][j];
        int fd=0;
        int prev=-1;
        REP(j,m){
            if (tb[i][j]!='.'){
                int val=tb[i][j]-'1'&2;
                if (!fd) prev=val;
                else if (val!=prev) res=0;

                fd=1;
            }
            prev^=2;
        }
        if (!fd) res=res*2%mod;
    }

    REP(i,m){
        int fd=0;
        int prev=-1;
        REP(j,n){
            if (tb[j][i]!='.'){
                int val=tb[j][i]-'1'&1;
                if (!fd) prev=val;
                else if (val!=prev) res=0;

                fd=1;
            }
            prev^=1;
        }
        if (!fd) res=res*2%mod;
    }

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


#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;

#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define AUTO(it, expr) __typeof__(expr) it = (expr)
#define FOR(it, c) for (AUTO(it, (c).begin()); (it) != (c).end(); ++(it))

const int LIM = 710;
typedef vector<int> vi;
vector<vi> hor, ver;
int n, m;

void bye() { cout << 0 << endl; exit(0); }

void fill_hor(int i, int j0, int t) {
    REP (j, m) {
	int s = t * (abs(j0 - j) & 1 ? -1 : 1);
	if (hor[i][j] == 0 || hor[i][j] == s) hor[i][j] = s;
	else bye();
    }
}

void fill_ver(int i0, int j, int t) {
    REP (i, n) {
	int s = t * (abs(i0 - i) & 1 ? -1 : 1);
	if (ver[i][j] == 0 || ver[i][j] == s) ver[i][j] = s;
	else bye();
    }
}

typedef unsigned int int_t;
typedef unsigned long long long_t;
int_t mod_expt(int_t a, int_t d, int_t n) {
    if (d == 0) return 1;
    else if (d & 1) return (long_t) a * mod_expt(a, d-1, n) % n;
    else return mod_expt((long_t) a*a%n, d/2, n);
}

const int MOD = 1000003;

int main() {
    cin >> n >> m;
    hor.resize(n, vi(m)); ver.resize(n, vi(m));
    REP (i, n) REP (j, m) {
	char c;
	cin >> c;
	switch (c) {
	case '1':
	    fill_hor(i, j, -1); fill_ver(i, j, -1); break;
	case '2':
	    fill_hor(i, j, -1); fill_ver(i, j, +1); break;
	case '3':
	    fill_hor(i, j, +1); fill_ver(i, j, +1); break;
	case '4':
	    fill_hor(i, j, +1); fill_ver(i, j, -1); break;
	case '.':
	    break;
	default:
	    assert(false);
	}
    }
    int h = 0, v = 0;
    REP (i, n) if (hor[i][0] == 0) ++h;
    REP (j, m) if (ver[0][j] == 0) ++v;
    cout << ((long_t) mod_expt(2, h, MOD) * mod_expt(2, v, MOD)) % MOD << endl;
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;

#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define AUTO(it, expr) __typeof__(expr) it = (expr)
#define FOR(it, c) for (AUTO(it, (c).begin()); (it) != (c).end(); ++(it))

const int LIM = 710;
typedef vector<int> vi;
vector<vi> hor, ver;
int n, m;

void bye() { cout << 0 << endl; exit(0); }

void fill_hor(int i, int j0, int t) {
    REP (j, m) {
	int s = t * (abs(j0 - j) & 1 ? -1 : 1);
	if (hor[i][j] == 0)
	     hor[i][j] = s;
	else {
	    if (hor[i][j] == s) return;
	    else bye();
	}
    }
}

void fill_ver(int i0, int j, int t) {
    REP (i, n) {
	int s = t * (abs(i0 - i) & 1 ? -1 : 1);
	if (ver[i][j] == 0)
	     ver[i][j] = s;
	else {
	    if (ver[i][j] == s) return;
	    else bye();
	}
    }
}

typedef unsigned int int_t;
typedef unsigned long long long_t;
int_t mod_expt(int_t a, int_t d, int_t n) {
    if (d == 0) return 1;
    else if (d & 1) return (long_t) a * mod_expt(a, d-1, n) % n;
    else return mod_expt((long_t) a*a%n, d/2, n);
}

const int MOD = 1000003;

int main() {
    scanf("%d%d", &n, &m);
    hor.resize(n, vi(m)); ver.resize(n, vi(m));
    REP (i, n) REP (j, m) {
	char c;
	scanf(" %c", &c);
	switch (c) {
	case '1':
	    fill_hor(i, j, -1); fill_ver(i, j, -1); break;
	case '2':
	    fill_hor(i, j, -1); fill_ver(i, j, +1); break;
	case '3':
	    fill_hor(i, j, +1); fill_ver(i, j, +1); break;
	case '4':
	    fill_hor(i, j, +1); fill_ver(i, j, -1); break;
	case '.':
	    break;
	default:
	    assert(false);
	}
    }
    int h = 0, v = 0;
    REP (i, n) if (hor[i][0] == 0) ++h;
    REP (j, m) if (ver[0][j] == 0) ++v;
    printf("%d\n", (int) mod_expt(2, h + v, MOD));
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;

#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define AUTO(it, expr) __typeof__(expr) it = (expr)
#define FOR(it, c) for (AUTO(it, (c).begin()); (it) != (c).end(); ++(it))

const int LIM = 710;
typedef vector<int> vi;
vector<vi> hor, ver;
int n, m;

void bye() { cout << 0 << endl; exit(0); }

void fill_hor(int i, int j0, int t) {
    REP (j, m) {
	int s = t * (abs(j0 - j) & 1 ? -1 : 1);
	if (hor[i][j] == 0 || hor[i][j] == s) hor[i][j] = s;
	else bye();
    }
}

void fill_ver(int i0, int j, int t) {
    REP (i, n) {
	int s = t * (abs(i0 - i) & 1 ? -1 : 1);
	if (ver[i][j] == 0 || ver[i][j] == s) ver[i][j] = s;
	else bye();
    }
}

typedef unsigned int int_t;
typedef unsigned long long long_t;
int_t mod_expt(int_t a, int_t d, int_t n) {
    if (d == 0) return 1;
    else if (d & 1) return (long_t) a * mod_expt(a, d-1, n) % n;
    else return mod_expt((long_t) a*a%n, d/2, n);
}

const int MOD = 1000003;

int main() {
    scanf("%d%d", &n, &m);
    hor.resize(n, vi(m)); ver.resize(n, vi(m));
    REP (i, n) REP (j, m) {
	char c;
	scanf(" %c", &c);
	switch (c) {
	case '1':
	    fill_hor(i, j, -1); fill_ver(i, j, -1); break;
	case '2':
	    fill_hor(i, j, -1); fill_ver(i, j, +1); break;
	case '3':
	    fill_hor(i, j, +1); fill_ver(i, j, +1); break;
	case '4':
	    fill_hor(i, j, +1); fill_ver(i, j, -1); break;
	case '.':
	    break;
	default:
	    assert(false);
	}
    }
    int h = 0, v = 0;
    REP (i, n) if (hor[i][0] == 0) ++h;
    REP (j, m) if (ver[0][j] == 0) ++v;
    cout << ((long_t) mod_expt(2, h, MOD) * mod_expt(2, v, MOD)) % MOD << endl;
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;

#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define AUTO(it, expr) __typeof__(expr) it = (expr)
#define FOR(it, c) for (AUTO(it, (c).begin()); (it) != (c).end(); ++(it))

const int LIM = 710;
int hor[LIM][LIM], ver[LIM][LIM];
int n, m;

void bye() { cout << 0 << endl; exit(0); }

void fill_hor(int i, int j0, int t) {
    REP (j, m) {
	int s = t * (abs(j0 - j) & 1 ? -1 : 1);
	if (hor[i][j] == 0 || hor[i][j] == s) hor[i][j] = s;
	else bye();
    }
}

void fill_ver(int i0, int j, int t) {
    REP (i, n) {
	int s = t * (abs(i0 - i) & 1 ? -1 : 1);
	if (ver[i][j] == 0 || ver[i][j] == s) ver[i][j] = s;
	else bye();
    }
}

typedef unsigned int int_t;
typedef unsigned long long long_t;
int_t mod_expt(int_t a, int_t d, int_t n) {
    if (d == 0) return 1;
    else if (d & 1) return (long_t) a * mod_expt(a, d-1, n) % n;
    else return mod_expt((long_t) a*a%n, d/2, n);
}

const int MOD = 1000003;

int main() {
    cin >> n >> m;
    REP (i, n) REP (j, m) {
	char c;
	cin >> c;
	switch (c) {
	case '1':
	    fill_hor(i, j, -1); fill_ver(i, j, -1); break;
	case '2':
	    fill_hor(i, j, -1); fill_ver(i, j, +1); break;
	case '3':
	    fill_hor(i, j, +1); fill_ver(i, j, +1); break;
	case '4':
	    fill_hor(i, j, +1); fill_ver(i, j, -1); break;
	case '.':
	    break;
	default:
	    assert(false);
	}
    }
    int h = 0, v = 0;
    REP (i, n) if (hor[i][0] == 0) ++h;
    REP (j, m) if (ver[0][j] == 0) ++v;
    cout << ((long_t) mod_expt(2, h, MOD) * mod_expt(2, v, MOD)) << endl;
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;

#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define AUTO(it, expr) __typeof__(expr) it = (expr)
#define FOR(it, c) for (AUTO(it, (c).begin()); (it) != (c).end(); ++(it))

const int LIM = 710;
int hor[LIM][LIM], ver[LIM][LIM];
int n, m;

void bye() { cout << 0 << endl; exit(0); }

void fill_hor(int i, int j0, int t) {
    REP (j, m) {
	int s = t * (abs(j0 - j) & 1 ? -1 : 1);
	if (hor[i][j] == 0 || hor[i][j] == s) hor[i][j] = s;
	else bye();
    }
}

void fill_ver(int i0, int j, int t) {
    REP (i, n) {
	int s = t * (abs(i0 - i) & 1 ? -1 : 1);
	if (ver[i][j] == 0 || ver[i][j] == s) ver[i][j] = s;
	else bye();
    }
}

typedef unsigned int int_t;
typedef unsigned long long long_t;
int_t mod_expt(int_t a, int_t d, int_t n) {
    if (d == 0) return 1;
    else if (d & 1) return (long_t) a * mod_expt(a, d-1, n) % n;
    else return mod_expt((long_t) a*a%n, d/2, n);
}

const int MOD = 1000003;

int main() {
    cin >> n >> m;
    REP (i, n) REP (j, m) {
	char c;
	cin >> c;
	switch (c) {
	case '1':
	    fill_hor(i, j, -1); fill_ver(i, j, -1); break;
	case '2':
	    fill_hor(i, j, -1); fill_ver(i, j, +1); break;
	case '3':
	    fill_hor(i, j, +1); fill_ver(i, j, +1); break;
	case '4':
	    fill_hor(i, j, +1); fill_ver(i, j, -1); break;
	case '.':
	    break;
	default:
	    assert(false);
	}
    }
    int h = 0, v = 0;
    REP (i, n) if (hor[i][0] == 0) ++h;
    REP (j, m) if (ver[0][j] == 0) ++v;
    cout << ((long_t) mod_expt(2, h, MOD) * mod_expt(2, v, MOD)) % MOD << endl;
}


#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;

#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define AUTO(it, expr) __typeof__(expr) it = (expr)
#define FOR(it, c) for (AUTO(it, (c).begin()); (it) != (c).end(); ++(it))

const int LIM = 710;
typedef vector<int> vi;
vector<vi> hor, ver;
int n, m;

void bye() { cout << 0 << endl; exit(0); }

void fill_hor(int i, int j0, int t) {
    REP (j, m) {
	int s = t * (abs(j0 - j) & 1 ? -1 : 1);
	if (hor[i][j] == 0 || hor[i][j] == s) hor[i][j] = s;
	else bye();
    }
}

void fill_ver(int i0, int j, int t) {
    REP (i, n) {
	int s = t * (abs(i0 - i) & 1 ? -1 : 1);
	if (ver[i][j] == 0 || ver[i][j] == s) ver[i][j] = s;
	else bye();
    }
}

typedef unsigned int int_t;
typedef unsigned long long long_t;
int_t mod_expt(int_t a, int_t d, int_t n) {
    if (d == 0) return 1;
    else if (d & 1) return (long_t) a * mod_expt(a, d-1, n) % n;
    else return mod_expt((long_t) a*a%n, d/2, n);
}

const int MOD = 1000003;

int main() {
    scanf("%d%d", &n, &m);
    hor.resize(n, vi(m)); ver.resize(n, vi(m));
    REP (i, n) REP (j, m) {
	char c;
	scanf(" %c", &c);
	switch (c) {
	case '1':
	    fill_hor(i, j, -1); fill_ver(i, j, -1); break;
	case '2':
	    fill_hor(i, j, -1); fill_ver(i, j, +1); break;
	case '3':
	    fill_hor(i, j, +1); fill_ver(i, j, +1); break;
	case '4':
	    fill_hor(i, j, +1); fill_ver(i, j, -1); break;
	case '.':
	    break;
	default:
	    assert(false);
	}
    }
    int h = 0, v = 0;
    REP (i, n) if (hor[i][0] == 0) ++h;
    REP (j, m) if (ver[0][j] == 0) ++v;
    printf("%d\n", (int) mod_expt(2, h + v, MOD));
}


#include<cstdio>
#include<vector>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int M=1000003;

int main(){
	int m,n;scanf("%d%d",&m,&n);
	vector< vector<char> > g(m,vector<char>(n));
	rep(i,m){
		scanf(" ");
		rep(j,n) scanf("%c",&g[i][j]);
	}

	static int row[500000],col[500000];
	rep(i,m) row[i]=3;
	rep(j,n) col[j]=3;

	rep(i,m) rep(j,n) if(g[i][j]!='.') {
		int d=g[i][j]-'0';
		row[i]&=1<<((d==1||d==2)^(j%2));
		col[j]&=1<<((d==2||d==3)^(i%2));
	}

	int ans=1;
	rep(i,m){
		if(row[i]==0) ans=0;
		if(row[i]==3) ans=2*ans%M;
	}
	rep(j,n){
		if(col[j]==0) ans=0;
		if(col[j]==3) ans=2*ans%M;
	}
	printf("%d\n",ans);

	return 0;
}


#include<cstdio>
#include<vector>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int M=1000003;

int main(){
	int m,n;scanf("%d%d",&m,&n);
	vector< vector<char> > g(m,vector<char>(n));
	rep(i,m){
		scanf(" ");
		rep(j,n) scanf("%c",&g[i][j]);
	}

	static int row[500000],col[500000];
	rep(i,m) row[i]=3;
	rep(j,n) col[j]=3;

	rep(i,m) rep(j,n) if(g[i][j]!='.') {
		int d=g[i][j]-'0';
		row[i]&=1<<((d==2||d==3)^(j%2));
		col[j]&=1<<((d==1||d==2)^(j%2));
	}

	int ans=1;
	rep(i,m){
		if(row[i]==0) ans=0;
		if(row[i]==3) ans=2*ans%M;
	}
	rep(j,n){
		if(col[j]==0) ans=0;
		if(col[j]==3) ans=2*ans%M;
	}
	printf("%d\n",ans);

	return 0;
}


#include<cstdio>
#include<cctype>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<bitset>
#include<map>
#include<set>
#include<complex>
#include<algorithm>
#include<functional>
#include<utility>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ(V) ((int)((V).size()))
typedef long long LL;
typedef unsigned long long ULL;
#define FEACH(I,S)		for(__typeof((S).begin()) I=(S).begin();I!=(S).end();++I)
#define REP(I,N)		for(I=0;I<(N);++I)
#define FN(I,N)			for(I=1;I<=(N);++I)
#define RREP(I,N)		for(I=(N)-1;I>=0;--I)
#define RFN(I,N)		for(I=(N);I;--I)
#define FAB(I,A,B)		for(I=(A);I<=(B);++I)
#define ANS(x)	return printf("%d\n",int(x)),0;
char tmps[512*1024];
const int MOD =1000003;
void db(int &x){x<<=1;if(x>=MOD)x%=MOD;}
int n,m,i,j;
int main(){
	scanf("%d%d ",&n,&m);
	vector<string> p;
	REP(i,n){
		gets(tmps);
		p.PB(string(tmps));
	}
	int ans = 1;
	REP(i,n){
		int mk=0;
		REP(j,m)if(p[i][j]!='.')
			mk|=(1<<((p[i][j]=='2'|| p[i][j]=='1')^(j&1)));
		if(mk==3)ANS(0);
		if(mk==0)db(ans);
	}
	REP(j,m){
		int mk=0;
		REP(i,n)if(p[i][j]!='.')
			mk|=(1<<((p[i][j]=='2'||p[i][j]=='3')^(i&1)));
		if(mk==3)ANS(0);
		if(mk==0)db(ans);
	}
	ANS(ans);
	return 0;
}


#include<cstdio>
#include<cctype>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<bitset>
#include<map>
#include<set>
#include<complex>
#include<algorithm>
#include<functional>
#include<utility>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ(V) ((int)((V).size()))
typedef long long LL;
typedef unsigned long long ULL;
#define FEACH(I,S)		for(__typeof((S).begin()) I=(S).begin();I!=(S).end();++I)
#define REP(I,N)		for(I=0;I<(N);++I)
#define FN(I,N)			for(I=1;I<=(N);++I)
#define RREP(I,N)		for(I=(N)-1;I>=0;--I)
#define RFN(I,N)		for(I=(N);I;--I)
#define FAB(I,A,B)		for(I=(A);I<=(B);++I)
#define ANS(x)	return printf("%d\n",int(x)),0;
char tmps[512*1024];
const int MOD =1000003;
void db(int &x){x<<=1;if(x>=MOD)x-MOD;}
int n,m,i,j;
int main(){
	scanf("%d%d ",&n,&m);
	vector<string> p;
	REP(i,n){
		gets(tmps);
		p.PB(tmps);
	}
	int ans = 1;
	REP(i,n){
		int mk=0;
		REP(j,m)if(p[i][j]!='.')
			mk|=1<<((p[i][j]<='2')^(j&1));
		if(mk == 3)ANS(0);
		if(mk == 0)db(ans);
	}
	REP(j,m){
		int mk=0;
		REP(i,n)if(p[i][j]!='.')
			mk|=1<<((p[i][j]>='2' && p[i][j]<='3')^(i&1));
		if(mk == 3)ANS(0);
		if(mk == 0)db(ans);
	}
	ANS(ans);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <iostream>
#include <sstream>

using namespace std;

typedef long long i64;
typedef unsigned long u32;
template<class T> int size(const T &a) {
	return int(a.size());
}
template<class T> T sqr(const T &a) {
	return a * a;
}
const int max_n = 600000;
char s[max_n + max_n];
char *a[max_n];
int row[max_n];
int col[max_n];
const int base = int(1e6 + 3.1);
int main() {
#ifdef pperm
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n, m;
	scanf("%d %d", &n, &m);
	char *p = s;
	for (int i = 0; i < n; i++) {
		scanf("%s", p);
		a[i] = p;
		p += strlen(p) + 1;
	}
	for (int i = 0; i < n; i++) {
		int c1 = 0, c2 = 0;
		for (int j = 0; j < m; j++) {
			if (a[i][j] != '.') {
				int d = a[i][j] - '0';
				if (d == 1 || d == 2) {
					if (j & 1)
						c1 = 1;
					else
						c2 = 1;
				} else {
					if (j & 1)
						c2 = 1;
					else
						c1 = 1;
				}
			}
		}
		if (c1 && c2) {
			printf("0");
			return 0;
		}
		if (!c1) {
			row[i] |= 1;
		}
		if (!c2) {
			row[i] |= 2;
		}
	}
	for (int j = 0; j < m; j++) {
		int c1 = 0, c2 = 0;
		for (int i = 0; i < n; i++) {
			if (a[i][j] != '.') {
				int d = a[i][j] - '0';
				if (d == 2 || d == 3) {
					if (i & 1)
						c1 = 1;
					else
						c2 = 1;
				} else {
					if (i & 1)
						c2 = 1;
					else
						c1 = 1;
				}
			}
		}
		if (c1 && c2) {
			printf("0");
			return 0;
		}
		if (!c1) {
			col[j] |= 1;
		}
		if (!c2) {
			col[j] |= 2;
		}
	}
	int r = 1;
	/*if (row[0] == 3) {
		if (col[0] == 3) {
			r = 4;
		}
		r = 2;
	} else {
		if (col[0] == 3) {
			r = 2;
		}
		r = 1;
	}*/
	for (int i = 0; i < n; i++) {
		if (row[i] == 3) {
			r = (r + r) % base;
		}
	}
	for (int j = 0; j < m; j++) {
		if (col[j] == 3) {
			r = (r + r) % base;
		}
	}
	cout << r;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <iostream>
#include <sstream>

using namespace std;

typedef long long i64;
typedef unsigned long u32;
template<class T> int size(const T &a) {
	return int(a.size());
}
template<class T> T sqr(const T &a) {
	return a * a;
}
const int max_n = 600000;
char s[max_n + max_n];
char *a[max_n];
int row[max_n];
int col[max_n];
const int base = int(1e6 + 3.1);
int main() {
#ifdef pperm
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n, m;
	scanf("%d %d", &n, &m);
	char *p = s;
	for (int i = 0; i < n; i++) {
		scanf("%s", p);
		a[i] = p;
		p += strlen(p) + 1;
	}
	for (int i = 0; i < n; i++) {
		int c1 = 0, c2 = 0;
		for (int j = 0; j < m; j++) {
			if (a[i][j] != '.') {
				int d = a[i][j] - '0';
				if (d == 1 || d == 2) {
					c1 = 1;
				} else {
					c2 = 1;
				}
			}
		}
		if (c1 && c2) {
			printf("0");
			return 0;
		}
		if (!c1) {
			row[i] |= 1;
		}
		if (!c2) {
			row[i] |= 2;
		}
	}
	for (int j = 0; j < m; j++) {
		int c1 = 0, c2 = 0;
		for (int i = 0; i < n; i++) {
			if (a[i][j] != '.') {
				int d = a[i][j] - '0';
				if (d == 2 || d == 3) {
					c1 = 1;
				} else {
					c2 = 1;
				}
			}
		}
		if (c1 && c2) {
			printf("0");
			return 0;
		}
		if (!c1) {
			col[j] |= 1;
		}
		if (!c2) {
			col[j] |= 2;
		}
	}
	int r = 1;
	/*if (row[0] == 3) {
		if (col[0] == 3) {
			r = 4;
		}
		r = 2;
	} else {
		if (col[0] == 3) {
			r = 2;
		}
		r = 1;
	}*/
	for (int i = 0; i < n; i++) {
		if (row[i] == 3) {
			r = (r + r) % base;
		}
	}
	for (int j = 0; j < m; j++) {
		if (col[j] == 3) {
			r = (r + r) % base;
		}
	}
	cout << r;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <iostream>
#include <sstream>

using namespace std;

typedef long long i64;
typedef unsigned long u32;
template<class T> int size(const T &a) {
	return int(a.size());
}
template<class T> T sqr(const T &a) {
	return a * a;
}
const int max_n = 600000;
char s[max_n + max_n];
char *a[max_n];
int row[max_n];
int col[max_n];
const int base = int(1e6 + 3.1);
int main() {
#ifdef pperm
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n, m;
	scanf("%d %d", &n, &m);
	char *p = s;
	for (int i = 0; i < n; i++) {
		scanf("%s", p);
		a[i] = p;
		p += strlen(p) + 1;
	}
	for (int i = 0; i < n; i++) {
		int c1 = 0, c2 = 0;
		for (int j = 0; j < m; j++) {
			if (a[i][j] != '.') {
				int d = (a[i][j] - '0') >> 1;
				if (d ^ (j & 1)) {
					c1 = 1;
				} else {
					c2 = 1;
				}
			}
		}
		if (c1 && c2) {
			printf("0");
			return 0;
		}
		if (!c1) {
			row[i] |= 1;
		}
		if (!c2) {
			row[i] |= 2;
		}
	}
	for (int j = 0; j < m; j++) {
		int c1 = 0, c2 = 0;
		for (int i = 0; i < n; i++) {
			if (a[i][j] != '.') {
				int d = (a[i][j] - '0') >> 1;
				if (d ^ (i & 1)) {
					c1 = 1;
				} else {
					c2 = 1;
				}
			}
		}
		if (c1 && c2) {
			printf("0");
			return 0;
		}
		if (!c1) {
			col[j] |= 1;
		}
		if (!c2) {
			col[j] |= 2;
		}
	}
	int r = 1;
	/*if (row[0] == 3) {
		if (col[0] == 3) {
			r = 4;
		}
		r = 2;
	} else {
		if (col[0] == 3) {
			r = 2;
		}
		r = 1;
	}*/
	for (int i = 0; i < n; i++) {
		if (row[i] == 3) {
			r = (r + r) % base;
		}
	}
	for (int j = 0; j < m; j++) {
		if (col[j] == 3) {
			r = (r + r) % base;
		}
	}
	cout << r;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <complex>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>

using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define FOR(i, a, b) for(int i(a), _b(b); i < _b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORD(i, a, b) for(int i(a), _b(b); i >= _b; --i)
#define CL(a, v) memset(a, v, sizeof a)
#define UNIQUE(a) sort(all(a)), (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define X first
#define Y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const ll INFLL = 1000000000000000000LL;

const int h = 500005, mod = 1000003;
int m, n, g0,g1, v0,v1;
int a[h];

void inc (int &a, int b) { a+=b; if(a>=mod) a-=mod; }

int main () {
#ifdef LocalHost
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
#endif
  scanf("%d%d", &n, &m);
  char c;
  REP(u, n*m) {
    c = 0;
    while(!isdigit(c) && c!='.') scanf("%c", &c);
    if(isdigit(c)) a[u] = c-'1';
    else a[u] = -1;
  }
  int ans = 1;
  REP(j, m) {
    v0 = v1 = 0;
    REP(i, n) {
      int u = i*m + j;
      if((i+j)%2==0) {
        if(a[u]==0 || a[u]==3) v0 |= 1;
        else if(a[u]!=-1) v0 |= 2;
      }
      else {
        if(a[u]==0 || a[u]==3) v1 |= 1;
        else if(a[u]!=-1) v1 |= 2;
      }
    }
    if((v0&v1)!=0) ans = 0;
    if((v0|v1)==0) inc(ans, ans);
  }
  REP(i, n) {
    g0 = g1 = 0;
    REP(j, m) {
      int u = i*m + j;
      if((i+j)%2==0) {
        if(a[u]==0 || a[u]==1) g0 |= 1;
        else if(a[u]!=-1) g0 |= 2;
      }
      else {
        if(a[u]==0 || a[u]==1) g1 |= 1;
        else if(a[u]!=-1) g1 |= 2;
      }
    }
    if((g0&g1)!=0) ans = 0;
    if((g0|g1)==0) inc(ans, ans);
  }
  printf("%d\n", ans);
#ifdef LocalHost
  cout << endl << "Time: " << clock() << endl;
#endif
  return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <complex>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>

using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define FOR(i, a, b) for(int i(a), _b(b); i < _b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORD(i, a, b) for(int i(a), _b(b); i >= _b; --i)
#define CL(a, v) memset(a, v, sizeof a)
#define UNIQUE(a) sort(all(a)), (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define X first
#define Y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const ll INFLL = 1000000000000000000LL;

const int h = 500005, mod = 1000003;
int m, n, g0,g1, v0,v1;
int a[h];

void inc (int &a, int b) { a+=b; if(a>=mod) a-=mod; }

int main () {
#ifdef LocalHost
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
#endif
  scanf("%d%d", &n, &m);
  char c;
  REP(u, n*m) {
    c = 0;
    while(!isdigit(c) && c!='.') scanf("%c", &c);
    if(isdigit(c)) a[u] = c-'1';
    else a[u] = -1;
  }
  int ans = 1;
  REP(j, m) {
    v0 = v1 = 0;
    REP(i, n) {
      int u = i*m + j;
      if((i+j)%2==0) {
        if(a[u]==0 || a[u]==3) v0 |= 1;
        else if(a[u]!=-1) v0 |= 2;
      }
      else {
        if(a[u]==0 || a[u]==3) v1 |= 1;
        else if(a[u]!=-1) v1 |= 2;
      }
    }
    if((v0&v1)!=0 || v0==3 || v1==3) ans = 0;
    if((v0|v1)==0) inc(ans, ans);
  }
  REP(i, n) {
    g0 = g1 = 0;
    REP(j, m) {
      int u = i*m + j;
      if((i+j)%2==0) {
        if(a[u]==0 || a[u]==1) g0 |= 1;
        else if(a[u]!=-1) g0 |= 2;
      }
      else {
        if(a[u]==0 || a[u]==1) g1 |= 1;
        else if(a[u]!=-1) g1 |= 2;
      }
    }
    if((g0&g1)!=0 || g0==3 || g1==3) ans = 0;
    if((g0|g1)==0) inc(ans, ans);
  }
  printf("%d\n", ans);
#ifdef LocalHost
  cout << endl << "Time: " << clock() << endl;
#endif
  return 0;
}


#include<stdio.h>
#include<string.h>

#define maxn 510000
#define div 1000003
int i,j,n,m;

int mp[maxn],t;

int attt(int a,int b){
        return mp[a*m+b];
}

bool sameheng(int a,int b){
        if(a>2)
                a=3;
        else
                a=1;
        if(b>2)
                b=3;
        else
                b=1;
        return a==b;
}

bool sameshu(int a,int b){
        if(a==4)
                a=1;
        if(a==3)
                a=2;
        if(b==4)
                b=1;
        if(b==3)
                b=2;
        return a==b;
}

bool check1(){
        int last;
        int lastc,nowc;
        for(i=0;i<n;i++){
                last=-1;
                for(j=0;j<m;j++){
                        nowc=attt(i,j);
                        if(nowc>=0){
                                if(last<0){
                                        last=j;
                                        lastc=nowc;
                                }
                                else{
                                        if(sameheng(lastc,nowc)){
                                                if((j-last)%2)
                                                        return false;
                                        }else{
                                                if((j-last)%2==0)
                                                        return false;
                                        }
                                        last=j;
                                        lastc=nowc;
                                }
                        }
                }
        }
        return true;
}
bool check2(){
        int last;
        int lastc,nowc;
        for(j=0;j<m;j++){
                last=-1;
                for(i=0;i<n;i++){
                        nowc=attt(i,j);
                        if(nowc>=0){
                                if(last<0){
                                        last=i;
                                        lastc=nowc;
                                }
                                else{
                                        if(sameshu(lastc,nowc)){
                                                if((i-last)%2)
                                                        return false;
                                        }else{
                                                if((i-last)%2==0)
                                                        return false;
                                        }
                                        last=i;
                                        lastc=nowc;
                                }
                        }
                }
        }
        return true;
}

int main(){
        scanf("%d %d",&n,&m);
        char temp;
        t=0;
        for(i=0;i<n;i++)
                for(j=0;j<m;j++){
                        scanf(" %c",&temp);
                        if(temp=='.')
                                mp[t]=-1;
                        else
                                mp[t]=temp-'0';
                        t++;
                }
        if(!(check1()&&check2())){
                printf("0\n");
                return 0;
        }

        int ans=1;

        for(i=0;i<n;i++){
                for(j=0;j<m;j++){
                        if(attt(i,j)>=0)
                                break;
                }
                if(j==m){
                        ans=ans+ans;
                        if(ans>=div)
                                ans-=div;
                }
        }
        for(j=0;j<m;j++){
                for(i=0;i<n;i++){
                        if(attt(i,j)>=0)
                                break;
                }
                if(i==n){
                        ans=ans+ans;
                        if(ans>=div)
                                ans-=div;
                }
        }
        printf("%d\n",ans);

        return 0;
}


#include<stdio.h>
#include<string.h>

#define maxn 510000
#define div 1000003
int i,j,n,m;

char mp[maxn],t;

char attt(int a,int b){
        return mp[a*m+b];
}

bool sameheng(char a,char b){
        if(a>2)
                a=3;
        else
                a=1;
        if(b>2)
                b=3;
        else
                b=1;
        return a==b;
}

bool sameshu(char a,char b){
        if(a==4)
                a=1;
        if(a==3)
                a=2;
        if(b==4)
                b=1;
        if(b==3)
                b=2;
        return a==b;
}

bool check1(){
        int last;
        char lastc,nowc;
        for(i=0;i<n;i++){
                last=-1;
                for(j=0;j<m;j++){
                        nowc=attt(i,j);
                        if(nowc>=0){
                                if(last<0){
                                        last=j;
                                        lastc=nowc;
                                }
                                else{
                                        if(sameheng(lastc,nowc)){
                                                if((j-last)%2)
                                                        return false;
                                        }else{
                                                if((j-last)%2==0)
                                                        return false;
                                        }
                                        last=j;
                                        lastc=nowc;
                                }
                        }
                }
        }
        return true;
}
bool check2(){
        int last;
        char lastc,nowc;
        for(j=0;j<m;j++){
                last=-1;
                for(i=0;i<n;i++){
                        nowc=attt(i,j);
                        if(nowc>=0){
                                if(last<0){
                                        last=i;
                                        lastc=nowc;
                                }
                                else{
                                        if(sameshu(lastc,nowc)){
                                                if((i-last)%2)
                                                        return false;
                                        }else{
                                                if((i-last)%2==0)
                                                        return false;
                                        }
                                        last=i;
                                        lastc=nowc;
                                }
                        }
                }
        }
        return true;
}

int main(){
        scanf("%d %d",&n,&m);
        for(i=0;i<n;i++)
                for(j=0;j<m;j++){
                        scanf(" %c",&mp[t]);
                        if(mp[t]=='.')
                                mp[t]=-1;
                        else
                                mp[t]-='0';
                        t++;
                }
        if(!(check1()&&check2())){
                printf("0\n");
                return 0;
        }

        int ans=1;

        for(i=0;i<n;i++){
                for(j=0;j<m;j++){
                        if(attt(i,j)>=0)
                                break;
                }
                if(j==m){
                        ans=ans+ans;
                        if(ans>=div)
                                ans-=div;
                }
        }
        for(j=0;j<m;j++){
                for(i=0;i<n;i++){
                        if(attt(i,j)>=0)
                                break;
                }
                if(i==n){
                        ans=ans+ans;
                        if(ans>=div)
                                ans-=div;
                }
        }
        printf("%d\n",ans);

        return 0;
}


#include<stdio.h>
#include<string.h>

#define maxn 5100000
#define div 1000003
int i,j,n,m;

char mp[maxn],t;

char at(int a,int b){
        return mp[a*m+b];
}

bool sameheng(char a,char b){
        if(a>2)
                a=3;
        else
                a=1;
        if(b>2)
                b=3;
        else
                b=1;
        return a==b;
}

bool sameshu(char a,char b){
        if(a==4)
                a=1;
        if(a==3)
                a=2;
        if(b==4)
                b=1;
        if(b==3)
                b=2;
        return a==b;
}

bool check1(){
        int last;
        char lastc,nowc;
        for(i=0;i<n;i++){
                last=-1;
                for(j=0;j<m;j++){
                        nowc=at(i,j);
                        if(nowc>=0){
                                if(last<0){
                                        last=j;
                                        lastc=nowc;
                                }
                                else{
                                        if(sameheng(lastc,nowc)){
                                                if((j-last)%2)
                                                        return false;
                                        }else{
                                                if((j-last)%2==0)
                                                        return false;
                                        }
                                        last=j;
                                        lastc=nowc;
                                }
                        }
                }
        }
        return true;
}
bool check2(){
        int last;
        char lastc,nowc;
        for(j=0;j<m;j++){
                last=-1;
                for(i=0;i<n;i++){
                        nowc=at(i,j);
                        if(nowc>=0){
                                if(last<0){
                                        last=i;
                                        lastc=nowc;
                                }
                                else{
                                        if(sameshu(lastc,nowc)){
                                                if((i-last)%2)
                                                        return false;
                                        }else{
                                                if((i-last)%2==0)
                                                        return false;
                                        }
                                        last=i;
                                        lastc=nowc;
                                }
                        }
                }
        }
        return true;
}

int main(){
        scanf("%d %d",&n,&m);
        for(i=0;i<n;i++)
                for(j=0;j<m;j++){
                        scanf(" %c",&mp[t]);
                        if(mp[t]=='.')
                                mp[t]=-1;
                        else
                                mp[t]-='0';
                        t++;
                }
        if(!(check1()&&check2())){
                printf("0\n");
                return 0;
        }

        int ans=1;

        for(i=0;i<n;i++){
                for(j=0;j<m;j++){
                        if(at(i,j)>=0)
                                break;
                }
                if(j==m){
                        ans=ans+ans;
                        if(ans>=div)
                                ans-=div;
                }
        }
        for(j=0;j<m;j++){
                for(i=0;i<n;i++){
                        if(at(i,j)>=0)
                                break;
                }
                if(i==n){
                        ans=ans+ans;
                        if(ans>=div)
                                ans-=div;
                }
        }
        printf("%d\n",ans);

        return 0;
}


#include<stdio.h>
#include<string.h>

#define maxn 510000
#define div 1000003
int i,j,n,m;

char mp[maxn],t;

char at(int a,int b){
        return mp[a*m+b];
}

bool sameheng(char a,char b){
        if(a>2)
                a=3;
        else
                a=1;
        if(b>2)
                b=3;
        else
                b=1;
        return a==b;
}

bool sameshu(char a,char b){
        if(a==4)
                a=1;
        if(a==3)
                a=2;
        if(b==4)
                b=1;
        if(b==3)
                b=2;
        return a==b;
}

bool check1(){
        int last;
        char lastc,nowc;
        for(i=0;i<n;i++){
                last=-1;
                for(j=0;j<m;j++){
                        nowc=at(i,j);
                        if(nowc>=0){
                                if(last<0){
                                        last=j;
                                        lastc=nowc;
                                }
                                else{
                                        if(sameheng(lastc,nowc)){
                                                if((j-last)%2)
                                                        return false;
                                        }else{
                                                if((j-last)%2==0)
                                                        return false;
                                        }
                                        last=j;
                                        lastc=nowc;
                                }
                        }
                }
        }
        return true;
}
bool check2(){
        int last;
        char lastc,nowc;
        for(j=0;j<m;j++){
                last=-1;
                for(i=0;i<n;i++){
                        nowc=at(i,j);
                        if(nowc>=0){
                                if(last<0){
                                        last=i;
                                        lastc=nowc;
                                }
                                else{
                                        if(sameshu(lastc,nowc)){
                                                if((i-last)%2)
                                                        return false;
                                        }else{
                                                if((i-last)%2==0)
                                                        return false;
                                        }
                                        last=i;
                                        lastc=nowc;
                                }
                        }
                }
        }
        return true;
}

int main(){
        scanf("%d %d",&n,&m);
        for(i=0;i<n;i++)
                for(j=0;j<m;j++){
                        scanf(" %c",&mp[t]);
                        if(mp[t]=='.')
                                mp[t]=-1;
                        else
                                mp[t]-='0';
                        t++;
                }
        if(!(check1()&&check2())){
                printf("0\n");
                return 0;
        }

        int ans=1;

        for(i=0;i<n;i++){
                for(j=0;j<m;j++){
                        if(at(i,j)>=0)
                                break;
                }
                if(j==m){
                        ans=ans+ans;
                        if(ans>=div)
                                ans-=div;
                }
        }
        for(j=0;j<m;j++){
                for(i=0;i<n;i++){
                        if(at(i,j)>=0)
                                break;
                }
                if(i==n){
                        ans=ans+ans;
                        if(ans>=div)
                                ans-=div;
                }
        }
        printf("%d\n",ans);

        return 0;
}


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

const int MOD = 1000003;

int main()
{
    int N, M;
    scanf("%d%d", &N, &M);

    vector<vector<char> > board(N, vector<char>(M));
    for(int i = 0; i < N; i++)
        for(int j = 0; j < M; j++)
            scanf(" %c", &board[i][j]);

    int ans = 1;
    for(int i = 0; i < N && ans; i++)
    {
        bool flag = true;
        for(int j = 0; j < M; j++)
            if(board[i][j] != '.')
            {
                flag = false;

                int d = (board[i][j] <= '2');
                if(j & 1)
                    d ^= 1;

                for(int k = 0; k < M; k++, d ^= 1)
                    if(board[i][k] != '.' && ((int)(board[i][k] <= '2')) != d)
                    {
                        ans = 0;
                        break;
                    }

                break;
            }
        if(flag)
            ans = (ans * 2) % MOD;
    }
    for(int j = 0; j < M && ans; j++)
    {
        bool flag = true;
        for(int i = 0; i < N; i++)
            if(board[i][j] != '.')
            {
                flag = false;
                int d = ('2' <= board[i][j] && board[i][j] <= '3');
                if(i & 1)
                    d ^= 1;
                for(int k = 0; k < N; k++, d ^= 1)
                    if(board[k][j] != '.' && ((int)('2' <= board[k][j] && board[k][j] <= '3')) != d)
                    {
                        ans = 0;
                        break;
                    }
                break;
            }
        if(flag)
            ans = (ans * 2) % MOD;
    }

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

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
#define fi first
#define se second
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define EPS 1E-9
#define x1 x111
#define y1 y111
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
int n,m;
vector< vector<int> > M;
vector< vector< set<int> > > U;
vector< vector<int> > S;
char BUF[1000000];
ll ans=0;
#define MOD 1000003
inline bool is_in(int x,int y){
  return (x>=0 && x<n && y>=0 && y<m);
}
ll TRY(int type){
  if(M[0][0]!=-1 && M[0][0]!=type)return 0;
  bool ch=true;
  if(M[0][0]!=-1)ch=false;
  else M[0][0]=type;
  for(int i=0;i<n;++i)
   for(int j=0;j<m;++j){
    U[i][j].clear();
    if(M[i][j]!=-1)U[i][j].insert(M[i][j]);
    else{
         U[i][j].insert(1);
         U[i][j].insert(2);
         U[i][j].insert(3);
         U[i][j].insert(4);
        }
                       }
  for(int i=0;i<n;++i)
   for(int j=0;j<m;++j){
    if(M[i][j]==1){
     if(is_in(i-1,j)){U[i-1][j].erase(1); U[i-1][j].erase(4); }
     if(is_in(i,j+1)){U[i][j+1].erase(1); U[i][j+1].erase(2); }
     if(is_in(i+1,j)){U[i+1][j].erase(1); U[i+1][j].erase(4); }
     if(is_in(i,j-1)){U[i][j-1].erase(1); U[i][j-1].erase(2); }
                  }
    //
    if(M[i][j]==2){
     if(is_in(i-1,j)){U[i-1][j].erase(2); U[i-1][j].erase(3); }
     if(is_in(i,j+1)){U[i][j+1].erase(1); U[i][j+1].erase(2); }
     if(is_in(i+1,j)){U[i+1][j].erase(2); U[i+1][j].erase(3); }
     if(is_in(i,j-1)){U[i][j-1].erase(1); U[i][j-1].erase(2); }
                  }
    //
    if(M[i][j]==3){
     if(is_in(i-1,j)){U[i-1][j].erase(2); U[i-1][j].erase(3); }
     if(is_in(i,j+1)){U[i][j+1].erase(3); U[i][j+1].erase(4); }
     if(is_in(i+1,j)){U[i+1][j].erase(2); U[i+1][j].erase(3); }
     if(is_in(i,j-1)){U[i][j-1].erase(3); U[i][j-1].erase(4); }
                  }
    //
    if(M[i][j]==4){
     if(is_in(i-1,j)){U[i-1][j].erase(1); U[i-1][j].erase(4); }
     if(is_in(i,j+1)){U[i][j+1].erase(3); U[i][j+1].erase(4); }
     if(is_in(i+1,j)){U[i+1][j].erase(1); U[i+1][j].erase(4); }
     if(is_in(i,j-1)){U[i][j-1].erase(3); U[i][j-1].erase(4); }
                  }
                       }
  bool WD=true;
  while(WD){
   WD=false;
   for(int i=0;i<n;++i)
    for(int j=0;j<m;++j)S[i][j]=U[i][j].size();
   for(int i=0;i<n;++i)
    for(int j=0;j<m;++j){
     int h1=U[i][j].count(1),h2=U[i][j].count(2),h3=U[i][j].count(3),h4=U[i][j].count(4);
     // up
     if(is_in(i-1,j)){
      if(!h2 && !h3)U[i-1][j].erase(1);
      if(!h1 && !h4)U[i-1][j].erase(2);
      if(!h1 && !h4)U[i-1][j].erase(3);
      if(!h2 && !h3)U[i-1][j].erase(4);
                     }
     // right
     if(is_in(i,j+1)){
      if(!h3 && !h4)U[i][j+1].erase(1);
      if(!h3 && !h4)U[i][j+1].erase(2);
      if(!h1 && !h2)U[i][j+1].erase(3);
      if(!h1 && !h2)U[i][j+1].erase(4);
                     }
     // down
     if(is_in(i+1,j)){
      if(!h2 && !h3)U[i+1][j].erase(1);
      if(!h1 && !h4)U[i+1][j].erase(2);
      if(!h1 && !h4)U[i+1][j].erase(3);
      if(!h2 && !h3)U[i+1][j].erase(4);
                     }
     // left
     if(is_in(i,j-1)){
      if(!h3 && !h4)U[i][j-1].erase(1);
      if(!h3 && !h4)U[i][j-1].erase(2);
      if(!h1 && !h2)U[i][j-1].erase(3);
      if(!h1 && !h2)U[i][j-1].erase(4);
                     }
                        }
    for(int i=0;i<n;++i)
     for(int j=0;j<m;++j)if(S[i][j]!=U[i][j].size()){WD=true; break;}
           }
  for(int i=0;i<n;++i)
   for(int j=0;j<m;++j)if(U[i][j].empty())return 0;
  ll ret=1;
  for(int i=1;i<n;++i){
   ret=ret*(U[i][0].size());
   ret%=MOD;
                      }
  for(int i=1;i<m;++i){
   ret=ret*(U[0][i].size());
   ret%=MOD;
                      }
  if(ch)M[0][0]=-1;
  return ret;
}
int main(){
  scanf("%d%d",&n,&m);
  M.resize( n, vector<int>(m,-1) );
  U.resize( n , vector< set<int> >(m) );
  S.resize( n , vector<int>(m) );
  for(int i=0;i<n;++i){
   scanf("%s",&BUF);
   for(int j=0;j<m;++j)
    if(BUF[j]!='.')M[i][j]=BUF[j]-'0';
                      }
  ans+=TRY(1); ans%=MOD;
  ans+=TRY(2); ans%=MOD;
  ans+=TRY(3); ans%=MOD;
  ans+=TRY(4); ans%=MOD;
  cout<<ans<<'\n';
  //system("pause");
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
#define fi first
#define se second
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define EPS 1E-9
#define x1 x111
#define y1 y111
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
int n,m;
vector< vector<int> > M;
vector< vector< set<int> > > U;
vector< vector<int> > S;
char BUF[1000000];
ll ans=0;
#define MOD 1000003
inline bool is_in(int x,int y){
  return (x>=0 && x<n && y>=0 && y<m);
}
ll TRY(int type){
  if(M[0][0]!=-1 && M[0][0]!=type)return 0;
  bool ch=true;
  if(M[0][0]!=-1)ch=false;
  else M[0][0]=type;
  for(int i=0;i<n;++i)
   for(int j=0;j<m;++j){
    U[i][j].clear();
    if(M[i][j]!=-1)U[i][j].insert(M[i][j]);
    else{
         U[i][j].insert(1);
         U[i][j].insert(2);
         U[i][j].insert(3);
         U[i][j].insert(4);
        }
                       }
  for(int i=0;i<n;++i)
   for(int j=0;j<m;++j){
    if(M[i][j]==1){
     if(is_in(i-1,j)){U[i-1][j].erase(1); U[i-1][j].erase(4); }
     if(is_in(i,j+1)){U[i][j+1].erase(1); U[i][j+1].erase(2); }
     if(is_in(i+1,j)){U[i+1][j].erase(1); U[i+1][j].erase(4); }
     if(is_in(i,j-1)){U[i][j-1].erase(1); U[i][j-1].erase(2); }
                  }
    //
    if(M[i][j]==2){
     if(is_in(i-1,j)){U[i-1][j].erase(2); U[i-1][j].erase(3); }
     if(is_in(i,j+1)){U[i][j+1].erase(1); U[i][j+1].erase(2); }
     if(is_in(i+1,j)){U[i+1][j].erase(2); U[i+1][j].erase(3); }
     if(is_in(i,j-1)){U[i][j-1].erase(1); U[i][j-1].erase(2); }
                  }
    //
    if(M[i][j]==3){
     if(is_in(i-1,j)){U[i-1][j].erase(2); U[i-1][j].erase(3); }
     if(is_in(i,j+1)){U[i][j+1].erase(3); U[i][j+1].erase(4); }
     if(is_in(i+1,j)){U[i+1][j].erase(2); U[i+1][j].erase(3); }
     if(is_in(i,j-1)){U[i][j-1].erase(3); U[i][j-1].erase(4); }
                  }
    //
    if(M[i][j]==4){
     if(is_in(i-1,j)){U[i-1][j].erase(1); U[i-1][j].erase(4); }
     if(is_in(i,j+1)){U[i][j+1].erase(3); U[i][j+1].erase(4); }
     if(is_in(i+1,j)){U[i+1][j].erase(1); U[i+1][j].erase(4); }
     if(is_in(i,j-1)){U[i][j-1].erase(3); U[i][j-1].erase(4); }
                  }
                       }
  bool WD=true;
  while(WD){
   WD=false;
   for(int i=0;i<n;++i)
    for(int j=0;j<m;++j)S[i][j]=U[i][j].size();
   for(int i=0;i<n;++i)
    for(int j=0;j<n;++j){
     int h1=U[i][j].count(1),h2=U[i][j].count(2),h3=U[i][j].count(3),h4=U[i][j].count(4);
     // up
     if(is_in(i-1,j)){
      if(!h2 && !h3)U[i-1][j].erase(1);
      if(!h1 && !h4)U[i-1][j].erase(2);
      if(!h1 && !h4)U[i-1][j].erase(3);
      if(!h2 && !h3)U[i-1][j].erase(4);
                     }
     // right
     if(is_in(i,j+1)){
      if(!h3 && !h4)U[i][j+1].erase(1);
      if(!h3 && !h4)U[i][j+1].erase(2);
      if(!h1 && !h2)U[i][j+1].erase(3);
      if(!h1 && !h2)U[i][j+1].erase(4);
                     }
     // down
     if(is_in(i+1,j)){
      if(!h2 && !h3)U[i+1][j].erase(1);
      if(!h1 && !h4)U[i+1][j].erase(2);
      if(!h1 && !h4)U[i+1][j].erase(3);
      if(!h2 && !h3)U[i+1][j].erase(4);
                     }
     // left
     if(is_in(i,j-1)){
      if(!h3 && !h4)U[i][j-1].erase(1);
      if(!h3 && !h4)U[i][j-1].erase(2);
      if(!h1 && !h2)U[i][j-1].erase(3);
      if(!h1 && !h2)U[i][j-1].erase(4);
                     }
                        }
    for(int i=0;i<n;++i)
     for(int j=0;j<m;++j)if(S[i][j]!=U[i][j].size()){WD=true; break;}
           }
  for(int i=0;i<n;++i)
   for(int j=0;j<m;++j)if(U[i][j].empty())return 0;
  ll ret=1;
  for(int i=1;i<n;++i){
   ret=ret*(U[i][0].size());
   ret%=MOD;
                      }
  for(int i=1;i<m;++i){
   ret=ret*(U[0][i].size());
   ret%=MOD;
                      }
  if(ch)M[0][0]=-1;
  return ret;
}
int main(){
  scanf("%d%d",&n,&m);
  M.resize( n, vector<int>(m,-1) );
  U.resize( n , vector< set<int> >(m) );
  S.resize( n , vector<int>(m) );
  for(int i=0;i<n;++i){
   scanf("%s",&BUF);
   for(int j=0;j<m;++j)
    if(BUF[j]!='.')M[i][j]=BUF[j]-'0';
                      }
  ans+=TRY(1); ans%=MOD;
  ans+=TRY(2); ans%=MOD;
  ans+=TRY(3); ans%=MOD;
  ans+=TRY(4); ans%=MOD;
  cout<<ans<<'\n';
  //system("pause");
  return 0;
}


#include <cstdio>
using namespace std;
#define MOD 1000003
#define SZ 500010
char BUF[SZ];
int n,m;
int up[SZ],down[SZ],L[SZ],R[SZ];
int main(){
  scanf("%d%d",&n,&m);
  for(int i=0;i<n;++i){
   scanf("%s",&BUF);
   for(int j=0;j<m;++j)
    switch(BUF[j]){
     case '1':
      if(j&1)R[i]=1;
      else L[i]=1;
      if(i&1)down[j]=1;
      else up[j]=1;
      break;
     case '2':
      if(j&1)R[i]=1;
      else L[i]=1;
      if(i&1)up[j]=1;
      else down[j]=1;
      break;
     case '3':
      if(j&1)L[i]=1;
      else R[i]=1;
      if(i&1)up[j]=1;
      else down[j]=1;
      break;
     case '4':
      if(j&1)L[i]=1;
      else R[i]=1;
      if(i&1)down[j]=1;
      else up[j]=1;
      break;
                     }
                  }
  int ans=1;
  for(int i=0;i<n;++i)ans=(ans*(2-L[i]-R[i]))%MOD;
  for(int i=0;i<m;++i)ans=(ans*(2-up[i]-down[i]))%MOD;
  printf("%d\n",ans);
  return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
#define MOD 1000003
char BUF[500010];
int n,m;
#define right RI
#define left LE
int up[500010],down[500010],left[500010],right[500010];
int main(){
  scanf("%d%d",&n,&m);
  for(int i=0;i<n;++i){
   scanf("%s",&BUF);
   for(int j=0;j<m;++j)
    switch(BUF[j]){
     case '1':
      if(j&1)right[i]=1;
      else left[i]=1;
      if(i&1)down[j]=1;
      else up[j]=1;
      break;
     case '2':
      if(j&1)right[i]=1;
      else left[i]=1;
      if(i&1)up[j]=1;
      else down[j]=1;
      break;
     case '3':
      if(j&1)left[i]=1;
      else right[i]=1;
      if(i&1)up[j]=1;
      else down[j]=1;
      break;
     case '4':
      if(j&1)left[i]=1;
      else right[i]=1;
      if(i&1)down[j]=1;
      else up[j]=1;
      break;
                     }
                  }
  int ans=1;
  for(int i=0;i<n;++i)ans=(ans*(2-left[i]-right[i]))%MOD;
  for(int i=0;i<m;++i)ans=(ans*(2-up[i]-down[i]))%MOD;
  printf("%d\n",ans);
  //system("pause");
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
#define fi first
#define se second
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define EPS 1E-9
#define x1 x111
#define y1 y111
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
int n,m;
vector< vector<int> > M;
vector< vector< set<int> > > U;
char BUF[1000000];
ll ans=0;
#define MOD 1000003
inline bool is_in(int x,int y){
  return (x>=0 && x<n && y>=0 && y<m);
}
ll TRY(int type){
  if(M[0][0]!=-1 && M[0][0]!=type)return 0;
  bool ch=true;
  if(M[0][0]!=-1)ch=false;
  else M[0][0]=type;
  for(int i=0;i<n;++i)
   for(int j=0;j<m;++j){
    U[i][j].clear();
    if(M[i][j]!=-1)U[i][j].insert(M[i][j]);
    else{
         U[i][j].insert(1);
         U[i][j].insert(2);
         U[i][j].insert(3);
         U[i][j].insert(4);
        }
                       }
  for(int i=0;i<n;++i)
   for(int j=0;j<m;++j){
    if(M[i][j]==1){
     if(is_in(i-1,j)){U[i-1][j].erase(1); U[i-1][j].erase(4); }
     if(is_in(i,j+1)){U[i][j+1].erase(1); U[i][j+1].erase(2); }
     if(is_in(i+1,j)){U[i+1][j].erase(1); U[i+1][j].erase(4); }
     if(is_in(i,j-1)){U[i][j-1].erase(1); U[i][j-1].erase(2); }
                  }
    //
    if(M[i][j]==2){
     if(is_in(i-1,j)){U[i-1][j].erase(2); U[i-1][j].erase(3); }
     if(is_in(i,j+1)){U[i][j+1].erase(1); U[i][j+1].erase(2); }
     if(is_in(i+1,j)){U[i+1][j].erase(2); U[i+1][j].erase(3); }
     if(is_in(i,j-1)){U[i][j-1].erase(1); U[i][j-1].erase(2); }
                  }
    //
    if(M[i][j]==3){
     if(is_in(i-1,j)){U[i-1][j].erase(2); U[i-1][j].erase(3); }
     if(is_in(i,j+1)){U[i][j+1].erase(3); U[i][j+1].erase(4); }
     if(is_in(i+1,j)){U[i+1][j].erase(2); U[i+1][j].erase(3); }
     if(is_in(i,j-1)){U[i][j-1].erase(3); U[i][j-1].erase(4); }
                  }
    //
    if(M[i][j]==4){
     if(is_in(i-1,j)){U[i-1][j].erase(1); U[i-1][j].erase(4); }
     if(is_in(i,j+1)){U[i][j+1].erase(3); U[i][j+1].erase(4); }
     if(is_in(i+1,j)){U[i+1][j].erase(1); U[i+1][j].erase(4); }
     if(is_in(i,j-1)){U[i][j-1].erase(3); U[i][j-1].erase(4); }
                  }
                       }
  for(int i=0;i<n;++i)
   for(int j=0;j<m;++j)if(U[i][j].empty())return 0;
  ll ret=1;
  for(int i=1;i<n;++i){
   ret=ret*(U[i][0].size());
   ret%=MOD;
                      }
  for(int i=1;i<m;++i){
   ret=ret*(U[0][i].size());
   ret%=MOD;
                      }
  if(ch)M[0][0]=-1;
  return ret;
}
int main(){
  scanf("%d%d",&n,&m);
  M.resize( n, vector<int>(m,-1) );
  U.resize( n , vector< set<int> >(m) );
  for(int i=0;i<n;++i){
   scanf("%s",&BUF);
   for(int j=0;j<m;++j)
    if(BUF[j]!='.')M[i][j]=BUF[j]-'0';
                      }
  ans+=TRY(1); ans%=MOD;
  ans+=TRY(2); ans%=MOD;
  ans+=TRY(3); ans%=MOD;
  ans+=TRY(4); ans%=MOD;
  cout<<ans<<'\n';
  //system("pause");
  return 0;
}


#include <cstdio>
using namespace std;
#define MOD 1000003
#define SZ 500010
char BUF[SZ];
int n,m;
int up[SZ],down[SZ],LE[SZ],RI[SZ];
int main(){
  scanf("%d%d",&n,&m);
  for(int i=0;i<n;++i){
   scanf("%s",&BUF);
   for(int j=0;j<m;++j)
    switch(BUF[j]){
     case '1':
      if(j&1)RI[i]=1;
      else LE[i]=1;
      if(i&1)down[j]=1;
      else up[j]=1;
      break;
     case '2':
      if(j&1)RI[i]=1;
      else LE[i]=1;
      if(i&1)up[j]=1;
      else down[j]=1;
      break;
     case '3':
      if(j&1)LE[i]=1;
      else RI[i]=1;
      if(i&1)up[j]=1;
      else down[j]=1;
      break;
     case '4':
      if(j&1)LE[i]=1;
      else RI[i]=1;
      if(i&1)down[j]=1;
      else up[j]=1;
      break;
                     }
                  }
  int ans=1;
  for(int i=0;i<n;++i)ans=(ans*(2-LE[i]-RI[i]))%MOD;
  for(int i=0;i<m;++i)ans=(ans*(2-up[i]-down[i]))%MOD;
  printf("%d\n",ans);
  return 0;
}


// --- BBG v2.0 ---
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<utility>
#include<map>
#include<set>
#include<string.h>
#include<string>
//
using namespace std;
//
//#define ONLINE_JUDGE BOBOGEI
#ifdef ONLINE_JUDGE
#define PP ;
#else
#define PP system("pause");
#endif
#define REP(n,i) for(int (i)=0;(i)<(n);(i)++)
#define CDREP(n,i) for(int (i)=((n)-1);(i)>=0;(i)--)
#define FOR(s,e,i) for(int (i)=(s);(i)<(e);(i)++)
#define SZ(n) memset((n),0,sizeof(n))
#define SMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define _F first
#define _S second
#define _MP(a,b) make_pair((a),(b))
#define _PB(a) push_back((a))
//
typedef unsigned int uint;
typedef long long i64;
typedef unsigned long long ui64;
typedef vector<int> vint;
typedef pair<int,int> pii;
const double PI = acos(-1.0);
const double EPS = 0.0000000304;
//
const int MAX=512345;
const int MOD=1000003;
//
int ipx[MAX],ipy[MAX];
int N,M;
int ans;
//
int main()
{
    SMO(ipx);
    SMO(ipy);
    ans=1;
    scanf("%d%d",&N,&M);
    getchar();
    char tc;
    int t;
    REP(N,i)
    {
        REP(M,j)
        {
            tc=getchar();
            if(tc=='.')
            {
                continue;
            }
            t=tc-'0';
            if(t<=2)
            {
                ipx[i*M+j]=0;
            }else
            {
                ipx[i*M+j]=1;
            }
            if(t==2||t==3)
            {
                ipy[i*M+j]=1;
            }else
            {
                ipy[i*M+j]=0;
            }
        }
        getchar();
    }
    REP(N,i)
    {
        int r=2,rf=-1;
        REP(M,j)
        {
            //printf("[%d]%d-",j,rf);
            if(ipx[i*M+j]!=-1)
            {
                if(rf!=-1&&rf!=ipx[i*M+j])
                {
                //  printf("%d",j);
                //  PP
                    puts("0");
                    return 0;
                }
                if(rf==-1)
                {
                    rf=ipx[i*M+j];
                    r=1;
                }
            }
            if(rf!=-1)
            {
                rf=1-rf;
            }

        }
        ans*=r;

        ans%=MOD;
    }

    REP(M,j)
    {
        int r=2,rf=-1;
        REP(N,i)
        {
            //printf("%d//",i*N+j);
            if(ipy[i*M+j]!=-1)
            {
                if(rf!=-1&&rf!=ipy[i*M+j])
                {
                    puts("0");
                    return 0;
                }
                if(rf==-1)
                {
                    //puts("123");
                    rf=ipy[i*M+j];
                    r=1;
                }
            }
            if(rf!=-1)
            {
                rf=1-rf;
            }
        }
        //printf("%d--",r);
        //PP
        ans*=r;
        ans%=MOD;
    }
    printf("%d\n",ans);
}


// --- BBG v2.0 ---
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<utility>
#include<map>
#include<set>
#include<string.h>
#include<string>
//
using namespace std;
//
//#define ONLINE_JUDGE BOBOGEI
#ifdef ONLINE_JUDGE
#define PP ;
#else
#define PP system("pause");
#endif
#define REP(n,i) for(int (i)=0;(i)<(n);(i)++)
#define CDREP(n,i) for(int (i)=((n)-1);(i)>=0;(i)--)
#define FOR(s,e,i) for(int (i)=(s);(i)<(e);(i)++)
#define SZ(n) memset((n),0,sizeof(n))
#define SMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define _F first
#define _S second
#define _MP(a,b) make_pair((a),(b))
#define _PB(a) push_back((a))
//
typedef unsigned int uint;
typedef long long i64;
typedef unsigned long long ui64;
typedef vector<int> vint;
typedef pair<int,int> pii;
const double PI = acos(-1.0);
const double EPS = 0.0000000304;
//
const int MAX=512345;
const int MOD=1000003;
//
int ipx[MAX],ipy[MAX];
int N,M;
int ans;
//
int main()
{
    SMO(ipx);
    SMO(ipy);
    ans=1;
    scanf("%d%d",&N,&M);
    getchar();
    char tc;
    int t;
    REP(N,i)
    {
        REP(M,j)
        {
            tc=getchar();
            if(tc=='.')
            {
                continue;
            }
            t=tc-'0';
            if(t<=2)
            {
                ipx[i*N+j]=0;
            }else
            {
                ipx[i*N+j]=1;
            }
            if(t==2||t==3)
            {
                ipy[i*N+j]=1;
            }else
            {
                ipy[i*N+j]=0;
            }
        }
        getchar();
    }
    REP(N,i)
    {
        int r=2,rf=-1;
        REP(M,j)
        {
            if(ipx[i*N+j]!=-1)
            {
                if(rf!=-1&&rf!=ipx[i*N+j])
                {

                    puts("0");
                    return 0;
                }
                if(rf==-1)
                {
                    rf=ipx[i*N+j];
                    r=1;
                }
            }
            if(rf!=-1)
            {
                rf=1-rf;
            }
        }
        ans*=r;

        ans%=MOD;
    }

    REP(M,j)
    {
        int r=2,rf=-1;
        REP(N,i)
        {
            //printf("%d//",i*N+j);
            if(ipy[i*N+j]!=-1)
            {
                if(rf!=-1&&rf!=ipy[i*N+j])
                {
                    puts("0");
                    return 0;
                }
                if(rf==-1)
                {
                    //puts("123");
                    rf=ipy[i*N+j];
                    r=1;
                }
            }
            if(rf!=-1)
            {
                rf=1-rf;
            }
        }
        //printf("%d--",r);
        //PP
        ans*=r;
        ans%=MOD;
    }
    printf("%d\n",ans);
}


#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;

vector < vector < int > > A;
vector < vector < int > > cnt;
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);

    A.resize(row+2);
    cnt.resize(row+2);
    for (i = 0; i < row+2; i++)
    {
        A[i].resize(col+2);
        cnt[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';
        }
    }

    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;
int row, col;

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;
}

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);
    for (i = 0; i < row+2; i++) A[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';
        }
    }

    int sum = 0;
    for (i = 1; i <= row; i++)
    {
        bool f = false;
        for (j = 1; j <= col; j++)
        {
            if (A[i][j]) f = true;
            if (!ok(i, j))
            {
                pr(0);
                return 0;
            }
        }
        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;
}