#include <bits/stdc++.h>
using namespace std;
int main() {
  int ind, i = 0, j = 0, r = 0, l = 0, minn = INT_MAX;
  string s;
  cin >> s;
  int a[s.size() + 1], b[s.size() + 1], fix[s.size() + 1];
  for (i = 0; i < s.size(); i++) {
    if (s[i] <= 'Z') r++;
  }
  for (i = 0; i < s.size(); i++) {
    if (i != 0)
      if (s[i - 1] >= 'a') l++;
    if (s[i] <= 'Z') r--;
    ind = l + r;
    if (minn > ind) minn = ind;
  }
  cout << minn;
}
