#include <bits/stdc++.h>
using namespace std;
char s[100005];
int a[100005];
int b[100005];
bool ok(char c) {
  if (c >= 'A' && c <= 'Z') {
    return 1;
  }
  return 0;
}
int main(int argc, char** argv) {
  int n;
  scanf(" %s", &s);
  n = strlen(s);
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  int num = 0;
  for (int i = 0; i < n; i++) {
    if (!ok(s[i])) {
      num++;
    }
    a[i] = num;
  }
  num = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (ok(s[i])) {
      num++;
    }
    b[i] = num;
  }
  int ans = 100005;
  for (int i = 0; i < n; i++) {
    ans = min(a[i] + b[i + 1], ans);
  }
  ans = min(b[0], ans);
  printf("%d\n", ans);
  return 0;
}
