#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, l, n, m, a[100005] = {0}, b[100005] = {0};
  char c[100005];
  cin >> c;
  n = strlen(c);
  for (i = 0; i < n; i++)
    if (c[i] >= 'a' && c[i] <= 'z')
      a[i + 1] = a[i] + 1;
    else
      a[i + 1] = a[i];
  for (i = n - 1; i >= 0; i--)
    if (c[i] >= 'A' && c[i] <= 'Z')
      b[i + 1] = b[i + 2] + 1;
    else
      b[i + 1] = b[i + 2];
  int mi = 100000000;
  for (i = 1; i <= n; i++) mi = min(mi, a[i] + b[i] - 1);
  cout << mi << endl;
  return 0;
}
