#include <bits/stdc++.h>
using namespace std;
bool inHoa(char x) {
  if (x >= 'A' && x <= 'Z') {
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  string s;
  int f[2][100001];
  cin >> s;
  int l = s.length();
  if (inHoa(s[0]) == 1) {
    f[0][0] = 0;
    f[1][0] = 1;
  } else {
    f[0][0] = 1;
    f[1][0] = 0;
  }
  for (int i = 1; i < l; i++) {
    if (inHoa(s[i]) == 1) {
      f[0][i] = f[0][i - 1];
      f[1][i] = min(f[0][i - 1], f[1][i - 1]) + 1;
    } else {
      f[0][i] = f[0][i - 1] + 1;
      f[1][i] = min(f[0][i - 1], f[1][i - 1]);
    }
  }
  cout << min(f[0][l - 1], f[1][l - 1]);
}
