#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 2000000000;
long long INFF = 8000000000000000000LL;
double PI = acos(-1);
inline string IntToString(int a) {
  char x[100];
  sprintf(x, "%d", a);
  string s = x;
  return s;
}
inline int StringToInt(string a) {
  char x[100];
  int res;
  strcpy(x, a.c_str());
  sscanf(x, "%d", &res);
  return res;
}
inline string GetString(void) {
  char x[1000005];
  scanf("%s", x);
  string s = x;
  return s;
}
inline bool angka(char a) { return (a >= '0' && a <= '9'); }
inline bool kecil(char a) { return (a >= 'a' && a <= 'z'); }
inline bool besar(char a) { return (a >= 'A' && a <= 'Z'); }
inline string uppercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); (i)++)
    if (kecil(s[i])) s[i] = s[i] - 'a' + 'A';
  return s;
}
inline string lowercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); (i)++)
    if (besar(s[i])) s[i] = s[i] - 'A' + 'a';
  return s;
}
string s;
int n, risan = INF;
int upper, uppernow;
int main() {
  s = GetString();
  n = (int)s.size();
  for (int(i) = (0); (i) < (n); (i)++)
    if (besar(s[i])) ++upper;
  if (upper == 0 || upper == n) {
    puts("0");
    return 0;
  }
  risan = upper;
  for (int(i) = (0); (i) < (n); (i)++) {
    if (besar(s[i])) ++uppernow;
    risan = min(risan, (i + 1) - uppernow + (upper - uppernow));
    ;
  }
  printf("%d\n", risan);
  return 0;
}
