#include <bits/stdc++.h>
using namespace std;
int sb, ss, pb, ps, n, ans;
char c[100001];
int main() {
  scanf("%s", &c);
  n = strlen(c);
  for (int i = 0; i < n; i++) {
    if (islower(c[i])) {
      ss++;
    } else {
      sb++;
    }
  }
  ans = sb;
  for (int i = 0; i < n; i++) {
    if (islower(c[i])) {
      ss--;
      ps++;
    } else {
      sb--;
      pb++;
    }
    ans = min(ans, ps + sb);
  }
  printf("%d\n", ans);
  return 0;
}
