#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=510; //check the limits, dummy
int a[N];
int n, m;
char c[N];
set<char> s[N+N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0; i<n; ++i){
		scanf("%s",c);
		for(int j=0; j<m; ++j){
			if(c[j]!='.')
				s[i+j].insert(c[j]);	
		}
	}
	ll ans = 1, mod = 998244353;
	for(int i=0; i<=n+m-2; ++i){
		if(s[i].size()==2){
			ans = 0;
			break;
		}
		else if(s[i].size()==0){
			ans *= 2;
			ans %= mod;
		}
	}
	printf("%lld\n",ans) ;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rrep(i,a,b) for(ll i=a;i>=b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846
#define fi first
#define se second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define all(x)  x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll mod = 998244353;
const ll inf = 1e18;

vector<ll> factorial;
void fill_factorial(ll n) {
    factorial.resize(n+1);
    factorial[0] = 1;
    for(ll i=1; i<=n; i++) factorial[i] = (factorial[i-1]*i)%mod;
}
ll gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
ll binpow(ll a, ll b) {
    a %= mod;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a%mod;
        a = a * a%mod;
        b >>= 1;
    }
    return res;
}
ll inv(ll a) {
	ll x, y;
	ll g = gcd(a, mod, x, y);
	x = (x % mod + mod) % mod;
	return x;
}
ll CC(ll n, ll k) {
    if(k>n) return 0LL;
    return factorial[n] * inv(factorial[k]) % mod * inv(factorial[n - k]) % mod;
}

void solve() {
    ll n; cin>>n;
    ll ans = 0;
    FOR(i,n) {
        ll a,b; cin>>a>>b;
        ans += (b*(b+1))/2 - (a*(a-1))/2;
    }
    cout<<ans<<"\n";
}

int main() {
	IOS; 
    #ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
    #endif
    
    //ll no_of_test_cases; cin>>no_of_test_cases; 
    ll no_of_test_cases = 1;
	while(no_of_test_cases--) {
      solve();
    } 
    return 0; 
}