#include <bits/stdc++.h>
using namespace std;
int l[200000], r[200000];
string s;
int ans = 1e9;
int main() {
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (islower(s[i])) l[i] = 1;
    if (i) l[i] += l[i - 1];
  }
  for (int i = n - 1; i >= 0; i--) {
    if (isupper(s[i])) r[i] = 1;
    if (i != n - 1) r[i] += r[i + 1];
  }
  ans = min(ans, l[n - 1]);
  ans = min(ans, r[0]);
  for (int i = 0; i < n - 1; i++) {
    ans = min(ans, l[i] + r[i + 1]);
  }
  cout << ans;
  return 0;
}
