#include <bits/stdc++.h>
using namespace std;
const int imax = INT32_MAX;
const int imin = INT32_MIN;
const long long int inf = 1e18;
const long long int MOD = 1e9 + 7;
const long long int range = 300;
vector<vector<int>> g;
template <class T>
T cal(T n) {
  return (n * 1ll * (n + 1));
}
template <class T>
T mx(T begin, T end) {
  return max_element(begin, end);
}
template <class T>
T mn(T begin, T end) {
  return min_element(begin, end);
}
template <class T>
void getUnique(vector<T>& nums) {
  sort(nums.begin(), nums.end());
  nums.erase(unique(nums.begin(), nums.end()), nums.end());
}
template <class T>
void print(vector<T> nums) {
  for (T i : nums) cout << i << " ";
  cout << "\n";
}
template <class T>
void read(vector<T>& nums) {
  for (T& i : nums) cin >> i;
}
template <class T>
vector<T> freq(vector<T> a, int b) {
  vector<T> nums(b + 1);
  for (T ele : a) nums[ele]++;
  return nums;
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long int t = 1;
  while (t--) {
    string s;
    cin >> s;
    int n = int((s).size());
    vector<vector<int>> pref(n + 1, vector<int>(2));
    for (int i = 0; i < n; ++i) {
      pref[i + 1][0] += pref[i][0];
      pref[i + 1][1] += pref[i][1];
      if (islower(s[i])) {
        pref[i + 1][0] += 1;
      } else {
        pref[i + 1][1] += 1;
      }
    }
    int ans = min(pref[n][0], pref[n][1]);
    for (int i = 0; i < n; ++i) {
      ans = min(ans, pref[i][0] + (pref[n][1] - pref[i + 1][1]));
    }
    cout << ans;
  }
  return 0;
}
