#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j;
  string s;
  cin >> s;
  n = s.length();
  long long int lower[n], upper[n], low[n], upp[n];
  if (s[0] >= 'a' && s[0] <= 'z') {
    lower[0] = 1;
    upper[0] = 0;
  } else {
    lower[0] = 0;
    upper[0] = 1;
  }
  for (i = 1; i < n; i++) {
    if (s[i] >= 'a' && s[i] <= 'z') {
      lower[i] = lower[i - 1] + 1;
      upper[i] = upper[i - 1];
    } else {
      lower[i] = lower[i - 1];
      upper[i] = upper[i - 1] + 1;
    }
  }
  if (s[n - 1] >= 'a' && s[n - 1] <= 'z') {
    low[n - 1] = 1;
    upp[n - 1] = 0;
  } else {
    low[n - 1] = 0;
    upp[n - 1] = 1;
  }
  for (i = n - 2; i >= 0; i--) {
    if (s[i] >= 'a' && s[i] <= 'z') {
      low[i] = low[i + 1] + 1;
      upp[i] = upp[i + 1];
    } else {
      low[i] = low[i + 1];
      upp[i] = upp[i + 1] + 1;
    }
  }
  long long int ans = LLONG_MAX;
  for (i = 0; i < n - 1; i++) {
    ans = min(ans, lower[i] + upp[i + 1]);
    ans = min(ans, lower[i] + low[i + 1]);
    ans = min(ans, upper[i] + upp[i + 1]);
  }
  if (ans == LLONG_MAX)
    cout << "0\n";
  else
    cout << ans << "\n";
}
