#include <bits/stdc++.h>
using namespace std;
char str[100010];
int a[100010];
int b[100010];
priority_queue<int, vector<int>, greater<int> > pq;
int main() {
  int i, j, k;
  while (gets(str) != NULL) {
    int len = strlen(str);
    int ma = 0, mi = 0;
    for (i = 0; i < len; i++) {
      if (str[i] <= 122 && str[i] >= 97) {
        a[i] = 1;
        ma++;
      }
      if (str[i] >= 65 && str[i] <= 90) {
        a[i] = 2;
        mi++;
      }
    }
    if (mi == 0 || ma == 0) {
      printf("0\n");
      continue;
    }
    int sum = min(mi, ma);
    int flag = 0;
    for (i = 0; i < len; i++) {
      if (a[i] == 2) {
        b[i] = 1;
        flag += 1;
      }
    }
    int k = flag;
    for (i = 0; i < len; i++) {
      if (b[i] == 1) {
        flag--;
      }
      if (b[i] == 0) {
        flag++;
      }
      if (flag < k) {
        k = flag;
      }
    }
    sum = min(sum, k);
    printf("%d\n", sum);
  }
  return 0;
}
