#include <bits/stdc++.h>
using namespace std;
void oinp() { freopen("a.inp", "r", stdin); }
void oout() { freopen("a.out", "w", stdout); }
string s;
int n, t, i, tt, b[1000000], bb[1000000], res1, res2;
int main() {
  cin >> n;
  cin >> s;
  s = " " + s;
  t = 0;
  for (i = 1; i <= n; i++)
    if (s[i] == 'H') t++;
  tt = n - t;
  b[0] = 0;
  res2 = 0;
  bb[0] = 0;
  for (i = 1; i <= n; i++) {
    if (s[i] == 'H')
      b[i] = b[i - 1] + 1;
    else
      b[i] = b[i - 1];
    bb[i] = i - b[i];
    if (i >= t && res1 < b[i] - b[i - t]) res1 = b[i] - b[i - t];
    if (i >= tt && res2 < bb[i] - bb[i - tt]) res2 = bb[i] - bb[i - tt];
  }
  cout << min(t - res1, tt - res2);
}
