#include <bits/stdc++.h>
using namespace std;
inline bool up(char c) { return isupper(c); }
inline bool low(char c) { return islower(c); }
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  string s;
  cin >> s;
  int len = s.length();
  vector<int> dp[2];
  dp[0].resize(len), dp[1].resize(len);
  dp[0][0] = low(s[0]), dp[1][0] = up(s[0]);
  for (int i = 1; s[i]; i++) {
    dp[0][i] = dp[0][i - 1] + low(s[i]);
    dp[1][i] = min(dp[0][i - 1], dp[1][i - 1]) + up(s[i]);
  }
  cout << min(dp[0][len - 1], dp[1][len - 1]) << '\n';
  return 0;
}
