#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000LL;
const double EPS = 1e-9;
const long long mod = 1000000007ll;
const int maxn = (int)300500 + 10;
int upPre[maxn], loPre[maxn];
int isUp(char x) { return ((x >> 5) & 1) == 0; }
int isLo(char x) { return ((x >> 5) & 1); }
int main() {
  char st[maxn];
  scanf("%s", st);
  int ln = strlen(st);
  for (int i = 1; i <= ln; i++)
    upPre[i] = upPre[i - 1] + isUp(st[i - 1]),
    loPre[i] = loPre[i - 1] + isLo(st[i - 1]);
  int ret = 123456789;
  for (int i = 0; i <= ln; i++) ret = min(ret, loPre[i] + upPre[ln] - upPre[i]);
  printf("%d\n", ret);
}
