#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cstdint>
#include <cmath>
using namespace std;
using ll = long long ;
#define LINF (1LL<<60)
#define rep(i,n) for (int i=0; i < (n); ++i)
//#define LLONG_MAX 9223372036854775807i64 

int ctoi(char c){
    return int(c)-int('0') ;
}

const int lim = 1e9 ;

int main() {
    int n ;
    cin >> n ;
    int  a[n] ;
    rep(i,n){
        cin >> a[i] ;
    }
    int ans = lim ;

    if(n==1){
        cout << a[0] << endl ; 
        return 0 ;
    }

    for (int bit = 0; bit < (1 << (n-1)); bit++) {
        int tot = 0 ;
        int cur = a[0] ;
        for (int i = 1; i < n ; i++) {
            if (bit & (1 << i-1)){
                tot ^= cur ;
                cur = a[i] ;
            }else{
                cur |= a[i] ;
            }
        }
        tot ^= cur ;
        ans = min(ans,tot) ;
    }

    cout << ans << endl ;
 return 0 ;
}  
    

#include <cmath>
#include <iostream>
#include <map>
#include <utility>
#include <vector>

#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using std::map;
using std::vector;

int main() {
    int h, w;
    cin >> h >> w;

    ll ans = 1;
    string s[h];
    REP(i, h) cin >> s[i];

    REP(sum, h + w) {
        int red = 0, blue = 0, empty = 0;
        REP(i, sum + 1) {
            if (i >= h) {
                continue;
            }
            int j = sum - i;
            if (j >= w) {
                continue;
            }
            char c = s[i][j];
            switch (c) {
                case 'B':
                    blue++;
                    break;
                case 'R':
                    red++;
                    break;
                case '.':
                    empty++;
                    break;
            }
        }
        if (red == 0 && blue == 0 && empty == 0) {
            continue;
        }
        if (red != 0 && blue != 0) {
            cout << 0;
            return 0;
        } else if (red == 0 && blue == 0) {
            ans *= 2;
            ans %= 998244353;
        }
    }
    cout << ans;

    return 0;
}