#include <bits/stdc++.h>
using namespace std;
string st;
int l, MIN;
int s1[110000], s2[110000];
int main() {
  cin >> st;
  l = st.size();
  for (int i = 1; i <= l; i++)
    if (st[i - 1] >= 'A' && st[i - 1] <= 'Z') {
      s1[i] = s1[i - 1] + 1;
      s2[i] = s2[i - 1];
    } else {
      s1[i] = s1[i - 1];
      s2[i] = s2[i - 1] + 1;
    }
  MIN = 2000000000;
  for (int i = 0; i <= l; i++) MIN = min(MIN, s2[i] + s1[l] - s1[i]);
  cout << MIN;
  return 0;
}
