#include <bits/stdc++.h>
using namespace std;
int N, M, T;
char str[1005];
int main() {
  int i, j, k;
  scanf("%d", &N);
  scanf("%s", str);
  for (i = 0; i < N; i++)
    if (str[i] == 'H') M++;
  int Mc = 1005;
  k = 0;
  for (i = 0; i < M; i++)
    if (str[i] != 'H') k++;
  int st = 0;
  if (k < Mc) Mc = k;
  for (i = M; i < N; i++) {
    if (str[st] != 'H') k--;
    st++;
    if (str[i] != 'H') k++;
    if (k < Mc) Mc = k;
  }
  M = 0;
  for (i = 0; i < N; i++)
    if (str[i] == 'T') M++;
  k = 0;
  for (i = 0; i < M; i++)
    if (str[i] == 'H') k++;
  st = 0;
  if (k < Mc) Mc = k;
  for (i = M; i < N; i++) {
    if (str[st] == 'H') k--;
    st++;
    if (str[i] == 'H') k++;
    if (k < Mc) Mc = k;
  }
  printf("%d\n", Mc);
  scanf(" ");
}
