#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length();
  int nlc = 0, nuc = 0;
  for (int i = 0; i < n; i++) {
    if (isupper(s[i]))
      nuc++;
    else
      nlc++;
  }
  if (nlc == n) {
    cout << "0";
    return 0;
  }
  int res = numeric_limits<int>::max();
  int uc = 0, lc = 0;
  for (int i = 0; i < n; i++) {
    if (isupper(s[i]))
      uc++;
    else
      lc++;
    res = min(res, lc + (nuc - uc));
  }
  cout << min(res, nuc);
  return 0;
}
