#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c < '0' || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
const int INF = 2e9;
const int MX = 100005;
const int MOD = 1000000007;
const double PI = acos(-1.0);
string s;
int dp[2][MX];
int solve(bool flag, int pos) {
  if (pos == (int)s.size()) return 0;
  if (dp[flag][pos] != -1) return dp[flag][pos];
  if (flag) {
    if (s[pos] >= 'A' && s[pos] <= 'Z')
      return dp[flag][pos] =
                 min(solve(true, pos + 1), 1 + solve(false, pos + 1));
    else
      return dp[flag][pos] =
                 min(1 + solve(true, pos + 1), solve(false, pos + 1));
  }
  return dp[flag][pos] =
             (s[pos] >= 'A' && s[pos] <= 'Z') + solve(false, pos + 1);
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> s;
  printf("%d\n", solve(true, 0));
  return 0;
}
