#include <bits/stdc++.h>
void Letter() {
  char str[100000 + 1];
  int Left[100000 + 1], Right[100000 + 1];
  int i, j;
  int Len;
  scanf("%s", str);
  Len = strlen(str);
  Left[0] = Right[Len - 1] = 0;
  for (i = 1; i < Len; i++)
    if (str[i - 1] <= 'z' && str[i - 1] >= 'a')
      Left[i] = Left[i - 1] + 1;
    else
      Left[i] = Left[i - 1];
  for (i = Len - 2; i >= 0; i--)
    if (str[i + 1] <= 'Z' && str[i + 1] >= 'A')
      Right[i] = Right[i + 1] + 1;
    else
      Right[i] = Right[i + 1];
  int min = INT_MAX;
  for (i = 0; i < Len; i++)
    if (min > Left[i] + Right[i]) min = Left[i] + Right[i];
  printf("%d\n", min);
}
int main() {
  Letter();
  return 0;
}
