#include <bits/stdc++.h>
using namespace std;
string a;
int change, low;
int main() {
  cin >> a;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] > 96)
      low++;
    else if (a[i] < 97 and low > 0) {
      if (change + 1 < low)
        change++;
      else
        change = low;
    }
  }
  cout << change;
}
