#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:5000000000")
const long long mod = 1000000007;
long long Inf = (long long)2e9;
long long LINF = (long long)1e18 + 1e17;
using namespace std;
long long n, m;
int main() {
  string s;
  cin >> s;
  n = s.size();
  int a = 0;
  int b = 0;
  for (int(i) = 0; (i) < n; (i)++) {
    if (s[i] >= 'a' && s[i] <= 'z')
      a++;
    else
      b++;
  }
  if (a == 0 || b == 0) {
    cout << 0;
    return 0;
  }
  int* count = new int[n + 1];
  int* Count = new int[n + 1];
  for (int i = 0; i <= n; i++) {
    count[i] = 0;
    Count[i] = 0;
  }
  count[0] = 0;
  Count[0] = 0;
  for (int i = 1; i <= n; i++) {
    count[i] = count[i - 1] + (s[i - 1] >= 'a' && s[i - 1] <= 'z');
    Count[i] = Count[i - 1] + (s[i - 1] >= 'A' && s[i - 1] <= 'Z');
  }
  int Min = n + 1;
  for (int i = 0; i <= n; i++) {
    Min = min(Min, count[i] + Count[n] - Count[i]);
  }
  cout << Min;
  return 0;
}
