#include <bits/stdc++.h>
char s[100005];
int up[100005], low[100005], mini, cnt;
int main() {
  while (scanf("%s", s + 1) == 1) {
    cnt = 0;
    mini = 100005;
    int ls = strlen(s + 1);
    for (int i = 1; s[i]; i++) {
      if (isupper(s[i])) cnt++;
      up[i] = cnt;
    }
    cnt = 0;
    for (int i = ls; s[i]; i--) {
      if (islower(s[i])) cnt++;
      low[i] = cnt;
    }
    int i;
    if (up[ls] == 0 || low[1] == 0)
      mini = 0;
    else {
      for (int i = 1; s[i]; i++) {
        int c = ls - up[i] - low[i];
        mini = (mini < c ? mini : c);
      }
    }
    printf("%d\n", mini);
  }
  return 0;
}
