#include <bits/stdc++.h>
using namespace std;
int u[100005] = {0};
int len = 0;
int main() {
  char s[100005];
  scanf("%s", s);
  u[0] = 0;
  if (isupper(s[0])) u[1] = 1;
  len = 1;
  for (int i = 1; s[i] != '\0'; i++) {
    u[i + 1] = u[i];
    if (isupper(s[i])) u[i + 1]++;
    len++;
  }
  int ans = 1000000000;
  for (int i = 0; i <= len; i++) {
    int x = u[len] - u[i];
    int y = i - u[i];
    ans = min(ans, (x + y));
  }
  printf("%d\n", ans);
  return 0;
}
