#include <bits/stdc++.h>
using namespace std;
int i, dp[100000], t;
string s;
int main() {
  cin >> s;
  for (i = 0; i < s.size(); i++)
    if (s[i] >= 'a') {
      dp[i] = dp[i - 1];
      t++;
    } else
      dp[i] = min(dp[i - 1] + 1, t);
  cout << dp[s.size() - 1] << endl;
  return 0;
}
