#include <bits/stdc++.h>
using namespace std;
char s[100010];
int sum[100010];
int main() {
  while (scanf("%s", s) == 1) {
    int len = strlen(s);
    int now = 0;
    for (int i = 0; i < len; i++) {
      if (s[i] >= 'A' && s[i] <= 'Z') now++;
      sum[i] = now;
    }
    int ans = sum[len - 1];
    for (int i = 0; i < len; i++) {
      int tans = (i + 1 - sum[i]) + (sum[len - 1] - sum[i]);
      ans = min(ans, tans);
    }
    printf("%d\n", ans);
  }
  return 0;
}
