#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}


char ff(char s, char t){
    if(s == t) return t;
    if(s != 'R' && t != 'R') return 'R';
    else if(s != 'B' && t != 'B') return 'B';
    else return 'W';
}

string g(string s){
    //cout << 1 csp si(s) csp s << endl;
    
    if(si(s) == 1) return s;
    
    int a = 1;
    int aa = a;
    while (a <= si(s)) {
        if((si(s)-1) % a == 0) chmax(aa,a);
        a *= 3;
    }
    
    string t = "";
    int b = 0;
    while (b+aa < si(s)) {
        t += ff(s[b],s[b+aa]);
        //cout << s[b] csp b csp s[b+aa] csp b+aa << " ";
        b += aa;
    }
    //cout << endl;
    if(si(t) == 1) return t;
    else return g(t);
}



int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    string s;
    cin >> s;
    
    cout << g(s) << endl;
    
    

    return 0;
}

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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

void Solve() {
    int n, m;
    cin >> n >> m;

    vector< vector<char> > grid(n + 1, vector<char>(m + 1));

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> grid[i][j];
        }
    }

    auto hasTopSide = [&](int r, int c) {
        return grid[r][c] == '#' && grid[r - 1][c] == '.';
    };

    auto hasBottomSide = [&](int r, int c) {
        return grid[r][c] == '#' && grid[r + 1][c] == '.';
    };

    auto hasLeftSide = [&](int r, int c) {
        return grid[r][c] == '#' && grid[r][c - 1] == '.';
    };

    auto hasRightSide = [&](int r, int c) {
        return grid[r][c] == '#' && grid[r][c + 1] == '.';
    };

    int answer = 0;

    for (int i = 2; i < n; ++i) {
        for (int j = 2; j < m; ++j) {
            if (grid[i][j] == '.') {
                continue;
            }

            if (hasBottomSide(i, j) && !hasBottomSide(i, j - 1)) {
                ++answer;
            }

            if (hasTopSide(i, j) && !hasTopSide(i, j - 1)) {
                ++answer;
            }

            if (hasLeftSide(i, j) && !hasLeftSide(i - 1, j)) {
                ++answer;
            }

            if (hasRightSide(i, j) && !hasRightSide(i - 1, j)) {
                ++answer;
            }
        }
    }

    cout << answer;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    //cin >> t;

    t = 1;

    while (t--) {
        Solve();
    }

    return 0;
}
