#include <bits/stdc++.h>
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::string str;
  std::cin >> str;
  std::uint64_t l = 0, r = str.size() - 1;
  while (l < str.size() && std::isupper(str[l])) l++;
  while (r && std::islower(str[r])) r--;
  std::uint64_t lower_total = 0, upper_total = 0;
  for (int i = l; i <= r; ++i)
    if (std::isupper(str[i]))
      upper_total++;
    else
      lower_total++;
  std::uint64_t ans = std::min(lower_total, upper_total), lower_count = 0,
                upper_count = 0;
  for (int i = l; i <= r; ++i) {
    if (std::islower(str[i])) {
      ans = std::min(ans, lower_count + upper_total - upper_count);
      lower_count++;
    } else
      upper_count++;
  }
  std::cout << ans;
  return 0;
}
