#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  string s;
  cin >> s;
  int n = (int)s.size();
  int L = 0, l = 0, U = 0, u = 0;
  for (int i = 0; i < n; i++)
    if (isupper(s[i]))
      U++;
    else
      L++;
  int ans = U;
  for (int i = 0; i < n; i++) {
    if (isupper(s[i])) {
      u++;
    } else
      l++;
    ans = min(ans, l + U - u);
  }
  cout << ans;
  cout << "\n";
}
