#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int INF = 1e9;
int main() {
  string s;
  cin >> s;
  long long n = s.length();
  vector<long long> v;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (int(s[i]) < 97) {
      v.push_back(1);
    } else {
      v.push_back(0);
    }
  }
  vector<long long> p = vector<long long>(n, 0);
  p[0] = (v[0] == 0) ? 1 : 0;
  for (long long i = 1; i < n; i++) {
    p[i] = p[i - 1] + ((v[i] == 0) ? 1 : 0);
  }
  long long mn = n - p[n - 1];
  for (long long i = 0; i < n; i++) {
    mn = min(mn, p[i] + (n - 1 - i - p[n - 1] + p[i]));
  }
  cout << mn << endl;
}
