#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int up[maxn], low[maxn], ans = maxn;
string str;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> str;
  int n = (int)(str).size();
  if (str[0] >= 'a' && str[0] <= 'z') up[0] = 1;
  for (int i = 1; i < n; ++i)
    up[i] = str[i] >= 'a' && str[i] <= 'z' ? up[i - 1] + 1 : up[i - 1];
  if (str[n - 1] >= 'A' && str[n - 1] <= 'Z') low[n - 1] = 1;
  for (int i = n - 2; i >= 0; --i)
    low[i] = str[i] >= 'A' && str[i] <= 'Z' ? low[i + 1] + 1 : low[i + 1];
  for (int i = 0; i < n; ++i) ans = min(ans, up[i] + low[i] - 1);
  cout << ans << '\n';
}
