#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e14;
const long long TE3 = 1005;
const long long TE5 = 100005;
int l[TE5], lrev[TE5], u[TE5], urev[TE5];
int main() {
  string s;
  cin >> s;
  int n = s.size(), lc = 0;
  if (islower(s[0])) {
    l[0] = 1;
    ++lc;
  } else {
    u[0] = 1;
  }
  for (int i = (1); i < (n); ++i) {
    if (islower(s[i])) {
      ++lc;
      l[i] = l[i - 1] + 1;
      u[i] = u[i - 1];
    } else {
      u[i] = u[i - 1] + 1;
      l[i] = l[i - 1];
    }
  }
  if (islower(s[n - 1])) {
    lrev[n - 1] = 1;
  } else {
    urev[n - 1] = 1;
  }
  for (int i = (n - 1); i > (-1); --i) {
    if (islower(s[i])) {
      lrev[i] = lrev[i + 1] + 1;
      urev[i] = urev[i + 1];
    } else {
      urev[i] = urev[i + 1] + 1;
      lrev[i] = lrev[i + 1];
    }
  }
  int mi = min(lc, n - lc);
  for (int i = (0); i < (n); ++i) {
    mi = min(mi, l[i] + urev[i + 1]);
  }
  cout << mi << endl;
  return 0;
}
