#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100000 + 5;
int DPUpper[MaxN], DPLower[MaxN];
string Str;
int main(void) {
  cin >> Str;
  int N = Str.length();
  for (int i = 0; i < N; i++) {
    DPUpper[i] = ('A' <= Str[i]) && (Str[i] <= 'Z');
    DPLower[i] = ('a' <= Str[i]) && (Str[i] <= 'z');
    if (i) {
      DPUpper[i] += DPUpper[i - 1];
      DPLower[i] += DPLower[i - 1];
    }
  }
  int Sol = DPLower[N - 1];
  for (int i = 0; i < N; i++) {
    int Curr = DPUpper[N - 1] - DPUpper[i];
    if (i) Curr += DPLower[i - 1];
    if (Curr < Sol) Sol = Curr;
  }
  cout << Sol << endl;
  return 0;
}
