#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 111111;
string a;
long long o = A, i, j, n, m, d[2][N];
long long get(long long k, long long l, long long r) {
  return d[k][r] - d[k][l - 1];
}
int main() {
  cin >> a;
  a = '*' + a, n = a.size();
  for (i = 1; i <= n; i++) {
    d[0][i] = d[0][i - 1], d[1][i] = d[1][i - 1];
    if (a[i] >= 'A' && a[i] <= 'Z')
      d[0][i]++;
    else
      d[1][i]++;
  }
  for (i = 0; i <= n; i++) o = min(o, d[1][i] + get(0, i + 1, n));
  cout << o;
}
