#include <bits/stdc++.h>
using namespace std;
string s;
int i, cll, a[100001], p;
int main() {
  cin >> s;
  int L = s.size();
  for (i = 0; i < L; i++) {
    if (s[i] >= 'a' && s[i] <= 'z') cll++;
    a[i] = cll;
  }
  int min = L - cll;
  if (cll == L)
    cout << 0;
  else {
    for (i = 0; i < L; i++) {
      p = 2 * a[i] + L - i - 1 - cll;
      if (p < min) min = p;
    }
    cout << min;
  }
  cout << endl;
}
