#include <bits/stdc++.h>
using namespace std;
void printprecise(double l, long long int precision) {
  std::cout << std::fixed;
  std::cout << std::setprecision(precision);
  std::cout << l;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long long int l = s.length();
  vector<long long int> a(l + 1), b(l + 1);
  for (long long int i = 1; i < l + 1; i++) {
    a[i] = a[i - 1];
    b[i] = b[i - 1];
    if (s[i - 1] >= 'a')
      a[i]++;
    else
      b[i]++;
  }
  long long int ops, min = 1000000007;
  for (long long int i = 0; i < l + 1; i++) {
    ops = a[i] + (b[l] - b[i]);
    if (ops < min) {
      min = ops;
    }
  }
  cout << min;
  return 0;
}
