#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;
string t;
int dp[MAX_N], d;
bool m;
int main() {
  cin >> t;
  dp[0] = 0;
  for (int i = 0; i < t.size(); i++) {
    int a = t[i];
    if (a > 91) {
      m = 1;
      d++;
    }
    dp[i] = dp[i - 1];
    if (m == 1 and a < 91) {
      dp[i]++;
      dp[i] = min(dp[i], d);
    }
  }
  cout << dp[t.size() - 1] << endl;
}
