#include <bits/stdc++.h>
using namespace std;
int dp[100006][2];
int main(void) {
  string s;
  cin >> s;
  int len = s.size();
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  dp[0][1] = 0;
  for (int i = 1; i <= len; ++i) {
    dp[i][1] = dp[i - 1][1] + (bool)islower(s[i - 1]);
    dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + (bool)isupper(s[i - 1]);
  }
  cout << min(dp[len][0], dp[len][1]);
  return 0;
}
