#include <iostream>
using namespace std;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int c = 0, d = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (s[i] == 'B' && s[i + 1] == 'B')
        {
            c++;
        }
        else if (i > 0 && s[i - 1] == 'B' && s[i + 1] == 'B')
        {
            d++;
        }
    }
    cout << n - 1 - max(0, c - 1) - d << endl;
}