#include <bits/stdc++.h>
using namespace std;
void dfs(set<long long>* sets, long long* arr, long long* visited) {}
int main() {
  long long t, ch, n, k, x, y, current_length, ch1, l, cop;
  string s;
  cin >> s;
  int* c_str = new int[s.length() + 5];
  int* c_pr = new int[s.length() + 5];
  if ((c_str[0] >= 'a') && (c_str[0] <= 'z'))
    c_str[0] = 1;
  else
    c_str[0] = 0;
  if ((c_pr[s.length() - 1] >= 'A') && (c_pr[s.length() - 1] <= 'Z'))
    c_pr[s.length() - 1] = 1;
  else
    c_pr[s.length() - 1] = 0;
  for (int i = 1; i < s.length(); i++) {
    if ((s[i - 1] <= 'z') && (s[i - 1] >= 'a'))
      c_str[i] = c_str[i - 1] + 1;
    else
      c_str[i] = c_str[i - 1];
  }
  for (int i = s.length() - 2; i >= 0; i--) {
    if ((s[i + 1] <= 'Z') && (s[i + 1] >= 'A'))
      c_pr[i] = c_pr[i + 1] + 1;
    else
      c_pr[i] = c_pr[i + 1];
  }
  int ans = 1e7;
  for (int i = 0; i < s.length(); i++) {
    ans = min(ans, c_str[i] + c_pr[i]);
  }
  cout << ans;
  return 0;
}
