#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long long int n, i, ans = 1000000007, x, y, l;
  n = s.length();
  long long int dp[n + 1];
  dp[0] = 0;
  for (i = 1; i <= n; i++) {
    if (s[i - 1] >= 'A' && s[i - 1] <= 'Z') {
      dp[i] = dp[i - 1] + 1;
    } else {
      dp[i] = dp[i - 1];
    }
  }
  for (i = 0; i <= n; i++) {
    x = (i - dp[i]);
    y = dp[n] - dp[i];
    ans = min(ans, x + y);
  }
  cout << ans << endl;
  return 0;
}
