#include <bits/stdc++.h>
using namespace std;
void prepare() {}
int n;
string s;
bool solve() {
  if (scanf("%d", &n) <= 0) return false;
  string g;
  cin >> s;
  g = s + s;
  int res = 1 << 20;
  for (int start = 0; start < n; start++) {
    s = g.substr(start, n);
    int p = n - 1;
    int k = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'T') {
        while (p >= 0 && s[p] == 'T') p--;
        if (p > i) {
          swap(s[i], s[p]);
          k++;
        } else
          break;
      }
    }
    res = min(res, k);
    s = g.substr(start, n);
    p = n - 1;
    k = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'H') {
        while (p >= 0 && s[p] == 'H') p--;
        if (p > i) {
          swap(s[i], s[p]);
          k++;
        } else
          break;
      }
    }
    res = min(res, k);
  }
  printf("%d\n", res);
  return true;
}
int main() {
  prepare();
  while (solve())
    ;
  return 0;
}
