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