#include <bits/stdc++.h>   using namespace std;   string str;   int memo[100005][3];   int dp(int Idx, int prev) {     if (Idx == (int)str.size()) return 0;     int choice1 = 1000000;     if (memo[Idx][prev] != -1) return memo[Idx][prev];     if (prev == 0) {       if (isupper(str[Idx]))         choice1 = dp(Idx + 1, 0) + 1;       else         choice1 = dp(Idx + 1, 0);     } else {       if (isupper(str[Idx])) {         choice1 = min(dp(Idx + 1, 0) + 1, dp(Idx + 1, 1));       } else         choice1 = min(dp(Idx + 1, 0), dp(Idx + 1, 1) + 1);     }     return memo[Idx][prev] = choice1;   }   int main() {     cin >> str;     memset(memo, -1, sizeof(memo));     int ans = dp(0, 1);     cout << ans << endl;     return 0;   }   