#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  string s1 = s;
  long long sum1 = 0, sum2 = 0, mn1 = 0, mn2 = 0;
  bool b = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] <= 'Z' && sum1 <= sum2) continue;
    if (s[i] >= 'a')
      sum1++;
    else
      sum2++;
  }
  cout << min(sum2, sum1);
}
