#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 8;
const int logN = 20, BL = 400;
const double EPS = 3e-16;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  long long n = ll(s.size());
  vector<long long> prefLower(n), suffUpper(n);
  prefLower[0] = ('a' <= s[0] && s[0] <= 'z');
  suffUpper[n - 1] = ('A' <= s[n - 1] && s[n - 1] <= 'Z');
  for (long long i = 1; i < n; i++) {
    prefLower[i] = prefLower[i - 1] + ('a' <= s[i] && s[i] <= 'z');
  }
  for (long long i = n - 2; i >= 0; i--) {
    suffUpper[i] = suffUpper[i + 1] + ('A' <= s[i] && s[i] <= 'Z');
  }
  long long ans = n;
  for (long long i = 0; i < n; i++) {
    ans = min(ans, prefLower[i] + suffUpper[i] - 1);
  }
  cout << ans;
  return 0;
}
