#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int n = s.length();
  vector<int> ans(n), lcount(n);
  if (s[0] >= 'a' && s[0] <= 'z')
    lcount[0] = 1;
  else
    lcount[0] = 0;
  ans[0] = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] >= 'a' && s[i] <= 'z')
      lcount[i] = lcount[i - 1] + 1;
    else
      lcount[i] = lcount[i - 1];
  }
  for (int i = 1; i < n; i++) {
    if (s[i] >= 'a' && s[i] <= 'z')
      ans[i] = ans[i - 1];
    else {
      ans[i] = min(ans[i - 1] + 1, lcount[i]);
    }
  }
  cout << ans[n - 1] << "\n";
  return 0;
}
