#include <bits/stdc++.h>
using namespace std;
int up[100005];
int low[100005];
int main() {
  string s;
  long long i, j, k, sum;
  while (cin >> s) {
    sum = 0;
    for (i = s.size() - 1; i >= 0; i--) {
      if (s[i] >= 'A' && s[i] <= 'Z') sum++;
      up[i] = sum;
    }
    long long max = 999999999;
    sum = 0;
    for (i = 0; i <= s.size(); i++) {
      if (s[i] >= 'a' && s[i] <= 'z') sum++;
      low[i] = sum;
    }
    for (i = s.size() - 1; i >= 0; i--) {
      if (max > up[i] + low[i]) max = up[i] + low[i];
    }
    cout << max - 1 << endl;
  }
}
