#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 100;
long long int u[MAXN];
long long int d[MAXN];
int ans = 999999999;
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] >= 'a') {
      u[i] = u[i - 1];
      d[i] = d[i - 1] + 1;
    } else {
      u[i] = u[i - 1] + 1;
      d[i] = d[i - 1];
    }
  }
  ans = min(d[s.size() - 1], u[s.size() - 1]);
  for (int i = 0; i < s.size(); i++) {
    int x = d[i];
    int y = u[s.size() - 1] - u[i];
    ans = min(ans, x + y);
  }
  cout << ans;
}
