#include <bits/stdc++.h>
using namespace std;
template <class T>
T nrem(T x, T y) {
  return ((x % y) + y) % y;
}
void in() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  in();
  string s;
  cin >> s;
  int len = s.length();
  int boro, choto;
  boro = choto = 0;
  for (int i = 0; i < len; ++i)
    if (s[i] >= 'A' && s[i] <= 'Z')
      boro++;
    else
      choto++;
  int x = 0, y = 0;
  if (boro == len || choto == len) return cout << 0 << "\n", 0;
  int ans = INT_MAX;
  for (int i = 0; i < len; ++i) {
    if (s[i] >= 'A' && s[i] <= 'Z')
      x++;
    else
      y++;
    ans = min(ans, boro - x + y);
  }
  cout << min(len - choto, min(len - boro, ans)) << "\n";
}
