#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int now = 0, ans = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (s[i] >= 'a')
      now++;
    else if (now > 0)
      now--, ans++;
  }
  cout << ans;
  return 0;
}
