#include <bits/stdc++.h>
using namespace std;
string arr;
int aux1[1000000], aux2[1000000];
int main() {
  int n;
  cin >> n;
  cin >> arr;
  int h = 0, t = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] == 'H') h++;
    aux1[i + 1] = h;
  }
  t = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] == 'T') t++;
    aux2[i + 1] = t;
  }
  int maxi1 = 0, maxi2 = 0;
  for (int i = h; i < n; i++) maxi1 = max(maxi1, aux1[i] - aux1[i - h]);
  for (int i = t; i < n; i++) maxi2 = max(maxi2, aux2[i] - aux2[i - t]);
  cout << min(h - maxi1, t - maxi2);
  return 0;
}
