#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
string s;
int x, dp[N][2];
int f(int i, bool lower) {
  if (i == x) return 0;
  if (dp[i][lower] != -1) return dp[i][lower];
  int mn = 1e9;
  bool valid = isupper(s[i]);
  if (!lower) {
    if (valid) {
      mn = min(mn, f(i + 1, 0));
      mn = min(mn, 1 + f(i + 1, 1));
    } else {
      mn = min(mn, f(i + 1, 1));
      mn = min(mn, 1 + f(i + 1, 0));
    }
  } else {
    if (valid)
      mn = min(mn, 1 + f(i + 1, 1));
    else
      mn = min(mn, f(i + 1, 1));
  }
  return dp[i][lower] = mn;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> s;
  x = s.size();
  memset(dp, -1, sizeof dp);
  cout << f(0, 0);
  return 0;
}
