#include <bits/stdc++.h>
using namespace std;
string s;
int n, caps[100010], smal[100010], ans;
int main() {
  cin >> s;
  s = "A" + s + "a";
  n = s.length();
  if ('a' <= s[0] && s[0] <= 'z') smal[0] = 1;
  for (int i = 1; i < n; i++) {
    smal[i] = smal[i - 1];
    if ('a' <= s[i] && s[i] <= 'z') smal[i]++;
  }
  if ('A' <= s[n - 1] && s[n - 1] <= 'Z') caps[n - 1] = 1;
  for (int i = n - 2; i >= 0; i--) {
    caps[i] = caps[i + 1];
    if ('A' <= s[i] && s[i] <= 'Z') caps[i]++;
  }
  ans = smal[0] + caps[1];
  for (int i = 1; i < n - 1; i++)
    if (ans > smal[i] + caps[i + 1]) ans = smal[i] + caps[i + 1];
  cout << ans;
}
