#include <bits/stdc++.h>
char str[1000000];
int main() {
  gets(str);
  int count1 = 0, count2 = 0;
  int l;
  int rez;
  for (l = 0; str[l]; l++) {
    if (str[l] >= 'A' && str[l] <= 'Z') {
      str[l] = 1;
      count1++;
    } else {
      str[l] = 2;
    }
  }
  if (count1 < l - count1) {
    rez = count1;
  } else {
    rez = l - count1;
  }
  for (int j = 0; j < l - 1; j++) {
    if (str[j] == 1) {
      count1--;
    } else {
      count2++;
    }
    if (str[j] < str[j + 1]) {
      if (rez > count1 + count2) {
        rez = count1 + count2;
      }
    }
  }
  printf("%d", rez);
  return 0;
}
