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