#include <bits/stdc++.h>
using namespace std;
char num[100010];
int cnt1[100010], cnt2[100010], ans = 0x3f3f3f3f, n;
int main() {
  scanf("%s", num + 1), n = strlen(num + 1);
  for (int i = 1; i <= n; i++)
    cnt1[i] = cnt1[i - 1] + ('a' <= num[i - 1] && num[i - 1] <= 'z'),
    cnt2[n - i + 1] =
        cnt2[n - i + 2] + ('A' <= num[n - i + 2] && num[n - i + 2] <= 'Z');
  for (int i = 1; i <= n; i++) ans = min(ans, cnt1[i] + cnt2[i]);
  printf("%d\n", ans);
}
