#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 long long N = 100005;
const long long MOD = 1e9 + 7;
long long dp[N][2];
string str;
long long n;
long long solve(long long pos, long long c) {
  if (pos >= n) return 0;
  if (dp[pos][c] != -1) return dp[pos][c];
  long long x = n;
  if (c == 1) {
    x = solve(pos + 1, 1) + (str[pos] > 'Z');
    x = min(x, solve(pos + 1, 0) + (str[pos] < 'a'));
  } else {
    x = min(x, solve(pos + 1, 0) + (str[pos] < 'a'));
  }
  return dp[pos][c] = x;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> str;
  n = str.size();
  cout << solve(0, 1) << endl;
}
