#include <bits/stdc++.h>
using namespace std;
string str;
int countt = 0;
bool lower(char a) {
  if ((int)a >= 97 && (int)a <= 122) return true;
  return false;
}
bool upper(char a) {
  if ((int)a >= 65 && (int)a <= 90) return true;
  return false;
}
int main() {
  int low = 0, delett = 0;
  cin >> str;
  for (int i = 0; i < str.length(); i++) {
    if (upper(str[i])) {
      if (low > 0) {
        delett++;
        low--;
      }
    }
    if (lower(str[i])) {
      low++;
    }
  }
  cout << delett;
}
