#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> c, p;
  p.push_back(0);
  int a, h = 0, t = 0;
  cin >> a;
  for (int i = 0; i < a; i++) {
    char q;
    cin >> q;
    if (q == 'H') {
      h++;
      c.push_back(0);
      p.push_back(p[p.size() - 1]);
    } else {
      t++;
      c.push_back(1);
      p.push_back(p[p.size() - 1] + 1);
    }
  }
  int ans = 10000;
  for (int i = h; i < p.size(); i++) {
    ans = min(ans, p[i] - p[i - h]);
  }
  for (int i = t; i < p.size(); i++) {
    ans = min(ans, t - (p[i] - p[i - t]));
  }
  cout << ans;
  return 0;
}
