#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  bool up = 0, lo = 0;
  int ans = INT_MAX;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (isupper(s[i])) up = 1;
    if (islower(s[i])) lo = 1;
  }
  if (up == 0 || lo == 0) {
    puts("0");
    return 0;
  }
  int cnt = 0;
  ans = 0;
  for (int i = 0; i < n; i++) {
    if (islower(s[i])) cnt++;
    if (isupper(s[i])) {
      if (cnt > 0) {
        cnt--, ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
