#include <bits/stdc++.h>
using namespace std;
char str[100030];
int main() {
  while (gets(str) != NULL) {
    int len = strlen(str), m, n1 = 0, n2 = 0;
    for (int i = 0; i < len; i++)
      if (str[i] >= 'a' && str[i] <= 'z')
        n2++;
      else
        n1++;
    int m1 = 0, m2 = 0;
    m = n1;
    for (int i = 1; i <= len; i++) {
      int k = 0;
      if (str[i - 1] >= 'a' && str[i - 1] <= 'z')
        m2++;
      else
        m1++;
      k += n1 - m1;
      k += m2;
      if (k < m) m = k;
    }
    printf("%d\n", m);
  }
  return 0;
}
