#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int sum = 0, n, U, L, curL, curU;
  cin >> s;
  L = U = curL = curU = 0;
  n = s.length();
  for (int i = 0; i < n; i++) {
    if (islower(s[i])) U++;
  }
  L = n - U;
  sum = L;
  curL = L;
  for (int i = 0; i < n; i++) {
    if (islower(s[i])) {
      curU++;
      sum = min(sum, curL + curU);
    } else {
      curL--;
      sum = min(sum, curL + curU);
    }
  }
  cout << sum << endl;
}
