#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e18 + 13;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  s = " " + s;
  vector<long long> low(s.size() + 2), up(s.size() + 2);
  for (int i = 1; i < s.size(); ++i)
    low[i] = (s[i] >= 'a') ? low[i - 1] + 1 : low[i - 1];
  for (int i = s.size() - 1; i >= 0; --i)
    up[i] = (s[i] <= 'Z') ? up[i + 1] + 1 : up[i + 1];
  long long res = oo;
  for (int i = 1; i <= s.size(); ++i) res = min(res, up[i] + low[i - 1]);
  cout << res << "\n";
}
