#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define INF LONG_MAX/3
//#define DIV 1000000007
//#define DIV 998244353

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//Aがindexの時に対応するB
ll A[210];
ll B[210];
set<ll> nums;

bool dp[205];

bool check(ll start, ll end) {
	ll l = end - start + 1;
	l/=2;

	for(ll i = start; i + l <= end; i++) {
		ll s = i;
		ll e = s + l;

		if(nums.count(s) && nums.count(e)) {
			if(A[s] == e && B[e] == s) continue;
			return false;

		} else if(nums.count(s)) {
			if(A[s] == 0) return false;

			if(A[s] == -1) continue;//ok

			if(A[s] != e) {
				return false;
			}


		} else if(nums.count(e)) {
			if(B[e] == 0) return false;

			if(B[e] == -1) continue;//ok

			if(B[e] != s) {
				return false;
			}
		} else {
			//-1, -1 ok

		}
	}
	return true;
}

int main(){
	ll N; cin >> N;
	rep(i, 210) A[i] = 0;
	rep(i, 210) B[i] = 0;

	rep(i, N) {
		ll a, b;
		cin >> a >> b;
		A[a] = b;
		B[b] = a;

		if(a != -1) {
			if(nums.count(a)) {
				cout << "No" << endl;
				return 0;
			}
			nums.insert(a);
		}

		if(b != -1) {
			if(nums.count(b)) {
				cout << "No" << endl;
				return 0;
			}
			nums.insert(b);
		}
	}

	dp[0] = true;

	for(ll i = 0; i <= 2*N; i++) {
		if(!dp[i]) continue;
		ll start = i + 1;
		for(ll end = start + 1; end <= 2*N; end += 2) {
			if(check(start, end)) {
				dp[end] = true;
			}
		}
	}
	if(dp[2*N]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#pragma GCC optimize("Ofast")
using namespace         std;
#define                 int long long
#define                 double long double
#define                 fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ArrayFill(arr,a)       memset(arr,a,sizeof arr)
#define                 endl '\n'              
#define countBit(x)     __builtin_popcountll(x)
#define all(x)          x.begin() , x.end()
#define ln              cout<<'\n';
using namespace std;
using namespace __gnu_pbds;  
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> oset; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; 

int ceil(int a,int b){return (a+b-1)/b;}
#define sim template < class c
#define ris return * this
#define dor > debug_ & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug_&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug_ {~debug_() { cerr << endl; }eni(!=) cerr << boolalpha << i; ris; }eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d){*this << "[";for (auto it = d.b; it != d.e; ++it)*this << ", " + 2 * (it == d.b) << *it;ris << "]";}};
#define db(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define debug(x) debug_() << db(x)
int modulo(int a,int b,int c){
    int x=1,y=a%c;
    while(b > 0){
        if(b%2 == 1)
            x=(x*y)%c;
        y = (y*y)%c;
        b = b>>1;
    }
    return  x%c;
}

// const int mod = 1e9 + 7ll;
const int mod = 998244353ll;
const int N = 505;
const int inf = 1e10;

string input[N];

void solve(){
    int n,m;
    cin >> n >> m;
    for(int i=0;i<n;i++){
        cin >> input[i];
    }    
    map<int,vector<char>>mp;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            mp[i+j].push_back(input[i][j]);
        }
    }
    int ans=1;
    for(auto &p:mp){
        int r{0},b{0},d{0};
        for(auto& i:p.second){
            if(i == 'R')r++;
            else if(i == 'B')b++;
            else d++;
        }
        if(r==0 && b==0){
            ans = (ans*2ll)%mod;
        }
        else if(r != 0 && b != 0){
            ans = 0;
        }
    }
    cout << ans;
}

signed main(){
    fast;
    int tt{1};
    // cin >> tt;
    for(int ii=1;ii<=tt;ii++){
        // cout << "Case #" << ii << ": ";
        solve();
        ln;
    }
    return 0;
}