#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length();
  vector<int> dp(n, 0);
  if (isupper(s[0])) dp[0] = 1;
  for (int i = 1; i < n; i++) {
    if (isupper(s[i])) {
      dp[i] = dp[i - 1] + 1;
    } else {
      dp[i] = dp[i - 1];
    }
  }
  int mn = INT_MAX;
  for (int i = 0; i < n; i++) {
    int s1 = 0;
    if (i == 0) {
      if (dp[i] == 0) {
        s1 = 0;
      } else {
        s1 = (i + 1) - dp[i];
      }
    } else
      s1 = (i + 1) - dp[i];
    int s2 = dp[n - 1] - dp[i];
    mn = min(s1 + s2, mn);
  }
  cout << mn << endl;
  return 0;
}
