#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
  return;
}
char c;
int a[10000005], cnt1, cnt2, cnt3, b[10000005], w[10000005], ans = 0x3f3f3f3f;
int main() {
  int lenth = read();
  for (register int i = 1; i <= lenth; ++i) {
    cin >> c;
    if (c == 'B') {
      a[i] = 1;
      b[i] = b[i - 1] + 1;
      w[i] = w[i - 1];
    } else {
      a[i] = 0;
      w[i] = w[i - 1] + 1;
      b[i] = b[i - 1];
    }
  }
  for (register int i = 0; i <= lenth; ++i)
    ans = min(ans, b[i] + w[lenth] - w[i + 1]);
  cout << ans;
  return 0;
}
