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