#include <bits/stdc++.h>
using namespace std;
int sumM[100000], summ[100000], ans = 123456789, l, m, M;
char s[100001];
int main() {
  scanf("%s", s);
  l = strlen(s);
  for (int i = l - 1; i > -1; i--) {
    sumM[i] = M;
    if (s[i] >= 'A' && s[i] <= 'Z') M++;
  }
  for (int i = 0; i < l; i++) {
    summ[i] = m;
    if (s[i] >= 'a' && s[i] <= 'z') m++;
  }
  for (int i = 0; i < l; i++) ans = min(ans, sumM[i] + summ[i]);
  printf("%d\n", ans);
  return 0;
}
