#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
char s[maxn];
int dp[maxn][2];
int main() {
  while (~scanf("%s", &s)) {
    int len = strlen(s);
    dp[0][0] = dp[0][1] = 0;
    if (isupper(s[0]))
      dp[0][1] = 1;
    else
      dp[0][0] = 1;
    for (int i = 1; i < len; i++) {
      if (isupper(s[i])) {
        dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + 1;
        dp[i][0] = dp[i - 1][0];
      } else {
        dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]);
        dp[i][0] = dp[i - 1][0] + 1;
      }
    }
    printf("%d\n", min(dp[len - 1][0], dp[len - 1][1]));
  }
}
