#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
string s;
bool a[MAXN];
int b[MAXN], c[MAXN], ans = 0x3f3f3f3f;
int main() {
  cin >> s;
  for (int i = 0; i < s.length(); i++)
    if (isupper(s[i])) a[i + 1] = 1;
  for (int i = 1; i <= s.length(); i++) b[i] += b[i - 1] + 1 - a[i];
  for (int i = s.length(); i >= 1; i--) c[i] += c[i + 1] + a[i];
  for (int i = 1; i <= s.length(); i++) ans = min(ans, b[i] + c[i]);
  cout << ans - 1 << endl;
  return 0;
}
