#include <bits/stdc++.h>
using namespace std;
int dp[100005][2];
string s;
void solve() {
  cin >> s;
  memset(dp, 0, sizeof(dp));
  int ans1, ans2;
  for (int i = 1; i <= (int)s.size(); i++) {
    if (s[i - 1] <= 90)
      dp[i][0] = dp[i - 1][0];
    else
      dp[i][0] = dp[i - 1][0] + 1;
    if (s[i - 1] >= 97)
      dp[i][1] = dp[i - 1][1];
    else
      dp[i][1] = min(dp[i - 1][1] + 1, dp[i][0]);
  }
  cout << dp[(int)s.size()][1] << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(NULL);
  solve();
  return 0;
}
