#include <bits/stdc++.h>
char str[1000000];
int numl[1000000], numb[1000000];
int main() {
  int i, j, l;
  while (scanf("%s", str) != EOF) {
    l = strlen(str);
    for (i = 0; i < 1000000; i++) {
      numl[i] = 0;
      numb[i] = 0;
    }
    for (i = 0; i < l; i++) {
      if (str[i] >= 'a' && str[i] <= 'z')
        numl[i + 1] = numl[i] + 1;
      else
        numl[i + 1] = numl[i];
    }
    for (i = l - 1; i >= 0; i--) {
      if (str[i] >= 'A' && str[i] <= 'Z')
        numb[i + 1] = numb[i + 2] + 1;
      else
        numb[i + 1] = numb[i + 2];
    }
    int max = 1000000000;
    for (i = 1; i <= l; i++) {
      if (numl[i] + numb[i] < max) max = numl[i] + numb[i];
    }
    printf("%d\n", max - 1);
  }
  return 0;
}
