#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[100010];
  int dp[2][100010] = {0};
  scanf("%s", s);
  int n = strlen(s);
  for (int i = 0; i < n; i++) {
    if (isupper(s[i])) {
      dp[0][i + 1] = 1 + min(dp[0][i], dp[1][i]);
      dp[1][i + 1] = dp[1][i];
    } else {
      dp[0][i + 1] = min(dp[0][i], dp[1][i]);
      dp[1][i + 1] = 1 + dp[1][i];
    }
  }
  printf("%d", min(dp[0][n], dp[1][n]));
  return 0;
}
