#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
char s[maxn];
int un[maxn], ln[maxn];
int main() {
  int i, j, k;
  int ans = INT_MAX, tmp;
  scanf("%s", s + 1);
  un[0] = ln[0] = 0;
  for (i = 1; s[i]; ++i) {
    if (islower(s[i])) {
      ln[i] = ln[i - 1] + 1;
      un[i] = un[i - 1];
    } else {
      ln[i] = ln[i - 1];
      un[i] = un[i - 1] + 1;
    }
  }
  int len = i - 1;
  for (i = 1; i <= len; ++i) {
    tmp = ln[i - 1] + un[len] - un[i];
    ans = min(ans, tmp);
  }
  printf("%d\n", ans);
  return 0;
}
