#include <bits/stdc++.h>
using namespace std;
int ans, i, a[200000], l;
string s;
int main() {
  ios::sync_with_stdio(0);
  cin >> s;
  l = s.size();
  for (i = 0; i < l; ++i)
    if (s[i] <= 'Z') a[i]++;
  for (i = 1; i < l; ++i) a[i] += a[i - 1];
  ans = a[l - 1];
  ans = min(ans, l - ans);
  for (i = 0; i < l; ++i) ans = min(ans, i - a[i] + 1 + a[l - 1] - a[i]);
  cout << ans;
  return 0;
}
