#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  string st;
  int c, s;
  cin >> st;
  int n = st.length();
  int cs[n], cc[n];
  int x = 0;
  for (int i = 0; i < n; i++) {
    if (int(st[i]) > 96) {
      x++;
      cs[i] = x;
    } else {
      cs[i] = x;
    }
  }
  x = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (int(st[i]) < 96) {
      x++;
      cc[i] = x;
    } else {
      cc[i] = x;
    }
  }
  s = cs[n - 1];
  c = cc[0];
  int ans[n];
  for (int i = 0; i < n; i++) {
    if (int(st[i]) > 96) {
      ans[i] = cc[i] + cs[i];
    } else {
      ans[i] = cc[i] + cs[i] - 1;
    }
  }
  sort(ans, ans + n);
  cout << min(ans[0], min(c, s));
}
