#include <bits/stdc++.h>
using namespace std;
int up[200005], low[200005];
int sum1[200005], sum2[200005];
int main() {
  ios::sync_with_stdio(false);
  string str;
  cin >> str;
  for (int i = 0; i < str.size(); i++)
    if (str[i] >= 'a' && str[i] <= 'z')
      low[i + 1] = 1;
    else
      up[i + 1] = 1;
  for (int i = str.size(); i >= 1; i--) sum1[i] = sum1[i + 1] + up[i + 1];
  for (int i = 1; i <= str.size(); i++) sum2[i] = sum2[i - 1] + low[i - 1];
  int ans = 2147483647;
  for (int i = 1; i <= str.size(); i++) ans = min(ans, sum1[i] + sum2[i]);
  cout << ans;
  return 0;
}
