#include <bits/stdc++.h>
using namespace std;
int small[100002], capital[100002];
int main() {
  string input;
  cin >> input;
  int n = input.size();
  memset(small, 0, sizeof(small));
  memset(capital, 0, sizeof(capital));
  for (int i = 1; i <= n; ++i) {
    small[i] = small[i - 1];
    if (islower(input[i - 1])) small[i]++;
    capital[i] = capital[i - 1];
    if (isupper(input[i - 1])) capital[i]++;
  }
  int ans = 100010;
  for (int i = 1; i <= n; ++i) {
    ans = min(small[i - 1] + capital[n] - capital[i - 1], ans);
  }
  ans = min(ans, small[n]);
  cout << ans;
  return 0;
}
