#include <bits/stdc++.h>
using namespace std;
string s;
int a[100005];
int b[100005];
int n;
int main() {
  cin >> s;
  n = s.size();
  for (int i = 1; i <= n; i++)
    if (s[i - 1] <= 'Z' && s[i - 1] >= 'A')
      a[i] = a[i - 1] + 1, b[i] = b[i - 1];
    else
      b[i] = b[i - 1] + 1, a[i] = a[i - 1];
  int best = n;
  for (int i = 0; i <= n; i++) {
    best = min(best, b[i] + a[n] - a[i]);
  }
  cout << best << endl;
}
