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