#include <bits/stdc++.h>
using namespace std;
int small[100010], big[100010];
int main() {
  string str;
  cin >> str;
  int len = str.size(), i, j, k;
  if (str[0] >= 'a' and str[0] <= 'z')
    small[0] = 1;
  else
    small[0] = 0;
  for (i = 1; i < len; i++) {
    if (str[i] >= 'a' and str[i] <= 'z')
      small[i] = small[i - 1] + 1;
    else
      small[i] = small[i - 1];
  }
  if (str[len - 1] >= 'A' and str[len - 1] <= 'Z')
    big[len - 1] = 1;
  else
    big[len - 1] = 0;
  for (i = len - 2; i >= 0; i--) {
    if (str[i] >= 'A' and str[i] <= 'Z')
      big[i] = 1 + big[i + 1];
    else
      big[i] = big[i + 1];
  }
  int ans = min(len - big[0], len - small[len - 1]);
  for (i = 0; i < len; i++) {
    ans = min(ans, small[i] + big[i + 1]);
  }
  cout << ans << endl;
  return 0;
}
