링크 : https://www.acmicpc.net/problem/2806
/*
문제 : DNA 발견
링크 : https://www.acmicpc.net/problem/2806
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int A[1000000];
int B[1000000];
int main() {
int n;
cin >> n;
vector<int> v;
for(int i = 0; i < n; i++){
char c;
cin >> c;
v.push_back(c);
}
if(v[0] == 'A'){
A[0] = 0;
B[0] = 1;
}
else{
A[0] = 1;
B[0] = 0;
}
for(int i = 1; i < n; i++){
if(v[i] == 'A'){
A[i] = min(A[i-1], B[i-1] + 1);
B[i] = min(A[i-1] + 1, B[i-1] + 1);
}
else{
A[i] = min(A[i-1] + 1, B[i-1] + 1);
B[i] = min(A[i-1] + 1, B[i-1]);
}
}
cout << A[n-1];
}