#include <bits/stdc++.h>
using namespace std;
string s;
int l, dp;
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    char c = s[i];
    int a = c;
    if (a > 96) {
      l++;
      continue;
    }
    if (a < 97 && l) {
      if (dp + 1 < l)
        dp++;
      else
        dp = l;
    }
  }
  cout << dp << endl;
  return 0;
}
