#include <bits/stdc++.h>
using namespace std;
int dp[100100][2];
int main() {
  string s;
  while (cin >> s) {
    int len = s.length();
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < len; i++) {
      if (isupper(s[i])) {
        dp[i][0] = min(dp[i - 1][0] + 1, dp[i - 1][1] + 1);
        dp[i][1] = dp[i - 1][1];
      } else {
        dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]);
        dp[i][1] = dp[i - 1][1] + 1;
      }
    }
    cout << min(dp[len - 1][0], dp[len - 1][1]) << endl;
  }
  return 0;
}
