#include <bits/stdc++.h>
using namespace std;
int main() {
  int i = 0, j = 0, in, cs;
  string s;
  cin >> s;
  int sz = s.size() + 5;
  int small[sz];
  int big[sz];
  memset(small, 0, sizeof(sz));
  memset(big, 0, sizeof(big));
  s[0] < 97 ? small[0] = 0 : small[0] = 1;
  s[s.size() - 1] < 97 ? big[s.size() - 1] = 1 : big[s.size() - 1] = 0;
  for (i = 1; i < s.size(); i++) {
    if (s[i] < 97)
      small[i] = small[i - 1];
    else
      small[i] = small[i - 1] + 1;
  }
  for (i = s.size() - 2; i >= 0; i--) {
    if (s[i] < 97)
      big[i] = big[i + 1] + 1;
    else
      big[i] = big[i + 1];
  }
  if (big[0] == 0 || small[s.size() - 1] == 0) {
    cout << 0 << "\n";
    return 0;
  }
  int MIN = INT_MAX;
  MIN = min(MIN, big[0]);
  MIN = min(MIN, small[s.size() - 1]);
  int a = 0;
  if (s[0] >= 97) a = 1;
  MIN = min(MIN, big[1] + a);
  if (s[s.size() - 1] >= 97)
    a = 1;
  else
    a = 0;
  MIN = min(MIN, small[s.size() - 2] + a);
  for (i = 1; i < s.size() - 1; i++) {
    int moves = small[i - 1] + big[i + 1];
    if (s[i] >= 97) moves++;
    MIN = min(MIN, moves);
  }
  cout << MIN << "\n";
  return 0;
}
