#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int cnt = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] >= 'a' && s[i] <= 'z') {
      cnt++;
    } else if (cnt > 0) {
      cnt--;
      ans++;
    }
  }
  cout << ans;
  return 0;
}
