#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long long n = s.length();
  vector<long long> prefix(n + 1, 0);
  for (long long i = 1; i <= n; i++) {
    if (isupper(s[i - 1]))
      prefix[i] = prefix[i - 1] + 1;
    else
      prefix[i] = prefix[i - 1];
  }
  long long ans = LLONG_MAX;
  for (long long i = 0; i <= n; i++) {
    long long up = i - prefix[i];
    long long down = prefix[n] - prefix[i];
    ans = min(ans, up + down);
  }
  cout << ans << endl;
  return 0;
}
