#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 10, inf = 1e18, mod = 1e9;
long long big;
long long res;
int main() {
  string x;
  cin >> x;
  for (int i = 0; i < x.size(); i++) {
    if (x[i] < 'a') big++;
  }
  res = big;
  long long ans[x.size()];
  ans[0] = big;
  if (x[0] < 'a')
    ans[0]--;
  else
    ans[0]++;
  res = min(res, ans[0]);
  for (int i = 1; i < x.size(); i++) {
    ans[i] = ans[i - 1];
    if (x[i] < 'a')
      ans[i]--;
    else
      ans[i]++;
    res = min(res, ans[i]);
  }
  cout << res;
  return 0;
}
