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