#include <bits/stdc++.h>
using namespace std;
string second;
const int maxn = 100100;
int pref[maxn];
int suff[maxn];
int main() {
  cin >> second;
  pref[0] = (second[0] >= 'a');
  for (int i = 1; i < second.size(); i++) {
    pref[i] = pref[i - 1];
    if (second[i] >= 'a') {
      pref[i]++;
    }
  }
  for (int i = second.size() - 1; i >= 0; i--) {
    suff[i] = suff[i + 1];
    if (second[i] < 'a') {
      suff[i]++;
    }
  }
  int mins = suff[0];
  for (int i = 0; i < second.size(); i++) {
    mins = min(mins, pref[i] + suff[i + 1]);
  }
  cout << mins << endl;
  return 0;
}
