#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
istream &operator>>(istream &is, pair<A, B> &p) {
  return is >> p.first >> p.second;
}
template <typename T_container, typename T = typename enable_if<
                                    !is_same<T_container, string>::value,
                                    typename T_container::value_type>::type>
istream &operator>>(istream &is, T_container &v) {
  for (T &x : v) is >> x;
  return is;
}
bool debug;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return debug ? os << '<' << p.first << "," << p.second << ">"
               : os << p.first << " " << p.second;
}
template <typename T_container, typename T = typename enable_if<
                                    !is_same<T_container, string>::value,
                                    typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v) {
  if (debug) {
    os << "[";
    string sep;
    for (const T &x : v) os << sep << x, sep = ", ";
    os << "]\n";
  } else {
    bool f = false;
    for (const T &x : v) {
      if (f) {
        os << " ";
      }
      os << x, f = true;
    }
  }
  return os;
}
template <typename T, typename T1, typename... Tail>
T amin(T &a, T1 b, Tail... c) {
  if (b < a) a = b;
  if constexpr (sizeof...(c) != 0) {
    amin(a, c...);
  }
  return a;
}
template <typename T, typename T1, typename... Tail>
T amax(T &a, T1 b, Tail... c) {
  if (b > a) a = b;
  if constexpr (sizeof...(c) != 0) {
    amax(a, c...);
  }
  return a;
}
void dbg_out() { cerr << "\n"; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
void solve() {
  string s;
  cin >> s;
  int n = (int)(s).size();
  vector<int> small(n, 0), cap(n + 1, 0);
  for (int i = 0; i < n; i++) {
    if (s[i] <= 'z' && s[i] >= 'a') small[i]++;
    if (i >= 1) small[i] += small[i - 1];
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] <= 'Z' && s[i] >= 'A') cap[i]++;
    if (i <= n - 2) cap[i] += cap[i + 1];
  }
  int ans = min(cap[0], small[n - 1]);
  for (int i = 0; i < n; i++) {
    ans = min(ans, cap[i + 1] + small[i]);
  }
  cout << ans << "\n";
}
void presolve() {}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tests = 1;
  presolve();
  while (tests-- > 0) solve();
  return 0;
}
