#include <bits/stdc++.h>
using namespace std;
int ans;
long long int x, y, cnt1, cnt2;
long long int power(long long int x, long long int y, long long int p) {
  long long int ans = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) ans = (ans * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return ans;
}
bool chk(long long int a) {
  long long int val1 = a / x;
  long long int val2 = a / y;
  long long int val3 = a / (x * y);
  long long int val4 = a - val1 - val2 + val3;
  val1 -= val3;
  val2 -= val3;
  long long int f1 = cnt1 - val2;
  long long int f2 = cnt2 - val1;
  if (f1 < 0) f1 = 0;
  if (f2 < 0) f2 = 0;
  return (f1 + f2 <= val4);
}
int fact(int n);
int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }
int fact(int n) {
  int res = 1;
  for (int i = 2; i <= n; i++) res = res * i;
  return res;
}
void jai_mata_di() {
  long long int n, k, a, b, flag = 0, x, y, i, j, ans = 0;
  string s;
  cin >> s;
  x = s.size();
  vector<long long int> low(x, 0);
  vector<long long int> up(x, 0);
  for (i = 0; i < x; i++) {
    if (s[i] >= 97)
      s[i] = 'a';
    else
      s[i] = 'A';
  }
  if (s[0] == 'a') low[0] = 1;
  if (s[x - 1] == 'A') up[n - 1] = 1;
  for (i = 1; i < x; i++) {
    if (s[i] == 'a')
      low[i] = low[i - 1] + 1;
    else
      low[i] = low[i - 1];
  }
  if (s[x - 1] == 'A') up[x - 1] = 1;
  for (i = x - 2; i >= 0; i--) {
    if (s[i] == 'A')
      up[i] = up[i + 1] + 1;
    else
      up[i] = up[i + 1];
  }
  ans = min(low[x - 1], up[0]);
  for (i = 1; i < x - 1; i++) ans = min(ans, low[i - 1] + up[i + 1]);
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int tt = 1.0 * clock();
  int t;
  t = 1;
  for (int y = 0; y < t; y++) {
    jai_mata_di();
    cout << endl;
  }
  return 0;
}
