#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int fact(int n) {
  if (n == 0 || n == 1)
    return 1;
  else
    return n * fact(n - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long m = 1000000;
  string s;
  cin >> s;
  int dp[100001][2] = {{0}};
  for (int i = s.length() - 1; i >= 0; i--) {
    if (s[i] >= 'a') {
      dp[i][0] = 1;
      dp[i][1] = 0;
    } else {
      dp[i][0] = 0;
      dp[i][1] = 1;
    }
    if (i == s.length() - 1) continue;
    dp[i][0] += dp[i + 1][0];
    dp[i][1] += dp[i + 1][1];
  }
  for (int i = 0; i <= s.length(); i++) {
    long long x;
    x = dp[i][1];
    x += (dp[0][0] - dp[i][0]);
    m = min(m, x);
  }
  cout << m;
  return 0;
}
