#include <bits/stdc++.h>
using namespace std;
int main() {
  int num1, num2, ans1, ans2, sum1, sum2, sum;
  num1 = num2 = ans1 = ans2 = sum1 = sum2 = 0;
  sum = 0x3f3f3f3f;
  char s[110000];
  int arr[110000];
  cin >> s;
  int len = strlen(s);
  for (int i = 0; i < len; ++i) {
    if (s[i] >= 'A' && s[i] <= 'Z')
      num1++;
    else
      num2++;
  }
  if (num2 == len || num1 == len)
    cout << 0 << endl;
  else {
    for (int i = 0; i < len; ++i) {
      if (s[i] >= 'A' && s[i] <= 'Z')
        sum1++;
      else
        sum2++;
      sum = min(sum2 + num1 - sum1, sum);
      if (sum1 == num1)
        sum = min(sum, sum1);
      else if (sum2 == num2)
        sum = min(sum, sum2);
    }
    cout << sum << endl;
  }
  return 0;
}
