#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
template <class T>
inline T sqr(T a) {
  return a * a;
}
bool isl(char c) { return c >= 'a' && c <= 'z'; }
int main() {
  string s;
  cin >> s;
  int n = s.length();
  int q = 0;
  for (int i = 0; i < n; ++i) {
    if (isl(s[i])) continue;
    ++q;
  }
  if (!q || q == n) {
    cout << 0;
    return 0;
  }
  int res = 1 << 20;
  int m = 0, b = 0;
  for (int i = 0; i < n; ++i) {
    int k = m + q - b;
    res = min(res, k);
    if (isl(s[i]))
      ++m;
    else
      ++b;
  }
  cout << min(res, min(n - q, q));
  return 0;
}
