#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  long long int n = s.size();
  long long int ap[n], bp[n], as[n];
  for (long long int i = 0; i < n; i++) {
    if (s[i] == 'a') {
      if (i != 0) {
        ap[i] = ap[i - 1];
        bp[i] = 1 + bp[i - 1];
      } else {
        ap[i] = 0;
        bp[i] = 1;
      }
    } else {
      if (i != 0) {
        ap[i] = 1 + ap[i - 1];
        bp[i] = bp[i - 1];
      } else {
        ap[i] = 1;
        bp[i] = 0;
      }
    }
    bp[i] = min(bp[i], ap[i]);
  }
  if (s[n - 1] == 'a') {
    as[n - 1] = 0;
  } else {
    as[n - 1] = 1;
  }
  for (long long int i = n - 2; i >= 0; i--) {
    if (s[i] == 'a') {
      as[i] = as[i + 1];
    } else {
      as[i] = 1 + as[i + 1];
    }
  }
  long long int ans = as[0];
  for (long long int i = 0; i < n - 1; i++) {
    ans = min(ans, bp[i] + as[i + 1]);
  }
  ans = min(ans, bp[n - 1]);
  cout << n - ans;
  return 0;
}
