#include <bits/stdc++.h>
char s[100001];
int a[100000];
int b[100000];
void func() {
  int n = strlen(s), i, ans = 1 << 29;
  if (isupper(s[0])) {
    a[0] = 0;
  } else {
    a[0] = 1;
  }
  for (i = 1; i < n; i++) {
    if (isupper(s[i])) {
      a[i] = a[i - 1];
    } else {
      a[i] = a[i - 1] + 1;
    }
  }
  if (islower(s[n - 1])) {
    b[n - 1] = 0;
  } else {
    b[n - 1] = 1;
  }
  for (i = n - 2; i >= 0; i--) {
    if (islower(s[i])) {
      b[i] = b[i + 1];
    } else {
      b[i] = b[i + 1] + 1;
    }
  }
  for (i = 0; i < n; i++) {
    if (i == 0) {
      ans = ((ans) < (b[i]) ? (ans) : (b[i]));
    }
    if (i < n - 1) {
      ans = ((ans) < (a[i] + b[i + 1]) ? (ans) : (a[i] + b[i + 1]));
    } else {
      ans = ((ans) < (a[i]) ? (ans) : (a[i]));
    }
  }
  printf("%d\n", ans);
}
int main() {
  while (scanf("%s", s) == 1) {
    func();
  }
  return 0;
}
