#include <bits/stdc++.h>
using namespace std;
const int N = 2147483647;
const int MOD = 1e8;
const int MAX = 100000;
void solve() {
  string s;
  cin >> s;
  int n = s.size();
  int dp[n][2];
  if (s[0] >= 'A' && s[0] <= 'Z') {
    dp[0][1] = 0;
    dp[0][0] = 1;
  } else {
    dp[0][1] = 1;
    dp[0][0] = 0;
  }
  for (int i = 1; i < n; i++) {
    if (s[i] >= 'A' && s[i] <= 'Z') {
      dp[i][1] = dp[i - 1][1];
      dp[i][0] = min(dp[i - 1][1], dp[i - 1][0]) + 1;
    } else {
      dp[i][1] = dp[i - 1][1] + 1;
      dp[i][0] = min(dp[i - 1][1], dp[i - 1][0]);
    }
  }
  cout << min(dp[n - 1][1], dp[n - 1][0]) << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
