#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1, n, i;
  string s;
  while (t--) {
    cin >> s;
    n = s.size();
    long long int pre[n], post[n], lower = 0, upper = 0;
    for (i = 0; i < n; i++) {
      pre[i] = lower;
      if (s[i] >= 'a' && s[i] <= 'z') lower++;
    }
    for (i = n - 1; i >= 0; i--) {
      post[i] = upper;
      if (s[i] >= 'A' && s[i] <= 'Z') upper++;
    }
    long long int ans = 1000000000000000000;
    for (i = 0; i < n; i++) ans = min(ans, pre[i] + post[i]);
    cout << ans;
  }
}
