#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5, INF = 1e9 + 9;
string s;
int low[MAXN], high[MAXN];
int main() {
  cin >> s;
  for (int i = 1; i <= (int)s.size(); i++) {
    low[i] = low[i - 1];
    high[i] = high[i - 1];
    if (s[i - 1] <= 'z' && s[i - 1] >= 'a')
      low[i]++;
    else
      high[i]++;
  }
  int ans = INF;
  for (int i = 0; i <= (int)s.size(); i++)
    ans = min(ans, i - high[i] + (high[(int)s.size()] - high[i]));
  printf("%d\n", ans);
}
