#include <bits/stdc++.h>
using namespace std;
long long int fastpow(long long int base, long long int exp, long long int M) {
  long long int res = 1;
  while (exp > 0) {
    if (exp & 1) res = (res * base) % M;
    base = (base * base) % M;
    exp >>= 1;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  long long int n = s.length(), x = 0, y = 0;
  for (long long int i = 0; i <= n - 1; ++i) {
    if (islower(s[i]))
      x++;
    else
      y++;
    if (x < y) x = y;
  }
  cout << n - x;
  return 0;
}
