#include <bits/stdc++.h>
using namespace std;
bool flag = true;
const long long int N = 3e5 + 5;
const long long int inf = 998244353;
void solve() {
  long long int i = 0, j = 0, ans = 0, x = 0, y = 0, z = 0;
  long long int n, k = 0, m = 0, mn = LLONG_MAX, mx = LLONG_MIN;
  string s;
  cin >> s;
  n = (long long int)s.size();
  vector<long long int> pref(1, 0);
  for (i = 0; i < n; i++) {
    if (s[i] <= 'z' && s[i] >= 'a')
      pref.push_back(pref.back() + 1);
    else
      pref.push_back(pref.back());
  }
  vector<long long int> suff(n + 2, 0);
  for (i = n; i >= 1; i--) {
    if (s[i - 1] >= 'A' && s[i - 1] <= 'Z')
      suff[i] = suff[i + 1] + 1;
    else
      suff[i] = suff[i + 1];
  }
  ans = suff[1];
  for (i = 1; i <= n; i++) {
    ans = min(ans, pref[i] + suff[i + 1]);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long int T = 1, te = 1;
  while (T--) {
    solve();
  }
  return 0;
}
