#include <bits/stdc++.h>
using namespace std;
const long long C = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t = 1;
  while (t--) {
    string s;
    cin >> s;
    long long small = 0, res = 0;
    for (long long i = 0; i < s.length(); i++) {
      if (s[i] >= 'a' && s[i] <= 'z')
        small++;
      else {
        if (small > 0) {
          small--;
          res++;
        }
      }
    }
    cout << res << "\n";
  }
  return 0;
}
