#include <bits/stdc++.h>
using namespace std;
const int _N = 1e5 + 11;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
string s;
int dp[_N][3], n;
int solve(int idx, int sma) {
  if (idx == n) return 0;
  if (dp[idx][sma] != -1) return dp[idx][sma];
  int res = INT_MAX;
  if (sma == 1) {
    if (s[idx] < 97) {
      res = min(res, 1 + solve(idx + 1, 1));
    } else {
      res = min(res, solve(idx + 1, 1));
    }
  } else {
    if (s[idx] < 97) {
      res = min(res, solve(idx + 1, 0));
      res = min(res, 1 + solve(idx + 1, 1));
    } else {
      res = min(res, solve(idx + 1, 1));
      res = min(res, 1 + solve(idx + 1, 0));
    }
  }
  return dp[idx][sma] = res;
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cout << fixed;
  cout << setprecision(15);
  srand(time(NULL));
  cin >> s;
  memset(dp, -1, sizeof dp);
  n = s.size();
  cout << min(solve(0, 0), solve(0, 1)) << '\n';
  return 0;
}
