#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  string s;
  cin >> s;
  long long c1 = 0, c2 = 0;
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] >= 'a' && s[i] <= 'z')
      c1++;
    else if (c1) {
      c1--;
      c2++;
    }
  }
  cout << c2 << "\n";
  return 0;
}
