#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int ph[N];
int main() {
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 1; i <= n; i++)
    ph[i] = ph[i - 1] + (s[i - 1] >= 'A' && s[i - 1] <= 'Z' ? 1 : 0);
  int ans = 1e5;
  for (int i = 0; i <= n; i++) {
    ans = min(ans, i - ph[i] + ph[n] - ph[i]);
  }
  cout << ans << endl;
  return 0;
}
