#include <bits/stdc++.h>
const long long inf64 = 0x3fffffff * (long long)0x3fffffff;
using namespace std;
int n;
char s[110000];
int h[110000], t[110000];
int main() {
  int i;
  int ans;
  while (scanf("%d", &n) != EOF) {
    scanf("%s", s + 1);
    ans = 0x3fffffff;
    h[0] = t[0] = 0;
    for (i = 1; i <= n; i++) {
      h[i] = h[i - 1];
      t[i] = t[i - 1];
      if (s[i] == 'H')
        h[i]++;
      else
        t[i]++;
    }
    for (i = 1; i + h[n] - 1 <= n; i++) {
      ans = min(ans, t[i + h[n] - 1] - t[i - 1]);
    }
    for (i = 1; i + t[n] - 1 <= n; i++) {
      ans = min(ans, h[i + t[n] - 1] - h[i - 1]);
    }
    printf("%d\n", ans);
  }
  return 0;
}
