#include <bits/stdc++.h>
using namespace std;
const int inf = 100500;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int dp1[n + 1], dp2[n + 1];
  memset(dp1, 0, sizeof(dp1));
  memset(dp2, 0, sizeof(dp2));
  for (int i = 1; i <= n; i++) {
    if (isupper(s[i - 1])) {
      dp1[i] = dp1[i - 1];
    } else {
      dp1[i] = dp1[i - 1] + 1;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (islower(s[i])) {
      dp2[i] = dp2[i + 1];
    } else {
      dp2[i] = dp2[i + 1] + 1;
    }
  }
  int ans = inf;
  for (int i = 0; i < n; i++) {
    ans = min(ans, dp1[i + 1] + dp2[i]);
  }
  cout << ans - 1 << endl;
  return 0;
}
