#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[100001][2];
  int n, i;
  string s;
  cin >> s;
  n = s.length();
  a[0][0] = a[0][1] = 0;
  for (i = 0; i < n; i++) {
    if (s[i] >= 'A' && s[i] <= 'Z') {
      a[i + 1][0] = a[i][0];
      a[i + 1][1] = min(a[i][1], a[i][0]) + 1;
    } else {
      a[i + 1][1] = min(a[i][0], a[i][1]);
      a[i + 1][0] = a[i][0] + 1;
    }
  }
  cout << min(a[n][0], a[n][1]) << endl;
}
