#include <bits/stdc++.h>
using namespace std;
int f(int i, int j, string s) {
  int n = s.size();
  char a = s[i];
  char b = s[j];
  int cnt = 0;
  while (i != j) {
    while (s[i] == a) {
      i = (i - 1 + n) % n;
      if (i == j) break;
    }
    if (i == j) break;
    while (s[j] == b) {
      j = (j + 1) % n;
      if (i == j) break;
    }
    if (i == j) break;
    swap(s[i], s[j]);
    cnt++;
  }
  return cnt;
}
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = INT_MAX;
  for (int i = 0; i < n; i++) {
    int j = (i + 1) % n;
    if (s[i] != s[j]) {
      int cnt = f(i, j, s);
      ans = min(ans, cnt);
    }
  }
  cout << ans << endl;
  return 0;
}
