#include <bits/stdc++.h>
using namespace std;
int a[100000];
int main() {
  int i = 0, j = 0, n = 0, m = 0, t = 0, k = 0, pass = 0, minn = 0;
  string s;
  cin >> s;
  n = s.size();
  for (i = 0; i < s.size(); i++) {
    if (s[i] >= 'a') {
      a[i] = a[i - 1];
      t++;
    } else {
      a[i] = min(a[i - 1] + 1, t);
    }
  }
  cout << a[n - 1] << endl;
}
