#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  string s;
  cin >> s;
  n = s.size();
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    if (isupper(s[i]))
      a[i]++;
    else
      b[i]++;
  }
  for (int i = 1; i < n; i++) a[i] += a[i - 1], b[i] += b[i - 1];
  int ans = n;
  for (int i = 0; i < n; i++) ans = min(ans, b[i] + a[n - 1] - a[i]);
  ans = min(ans, a[n - 1] - a[0]);
  cout << ans;
}
