#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T>
T gcd(T a, T b) {
  T m;
  while (b != T(0)) {
    m = a % b;
    a = b;
    b = m;
  }
  return a;
}
template <typename T>
T lcm(T a, T b) {
  return a == 0 && b == 0 ? 0 : (a / gcd(a, b)) * b;
}
int solve() {
  string s;
  cin >> s;
  int n = s.size();
  std::vector<int> va(1 + n);
  va[0] = 0;
  for (int i = 1; i <= n; ++i) va[i] = va[i - 1] + (s[i - 1] == 'a' ? 1 : 0);
  if (va[n] == n) {
    printf("%d\n", n);
    return 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      int na = va[i - 1], nb = (j - i + 1) - (va[j] - va[i - 1]),
          nc = va[n] - va[j];
      int total = na + nb + nc;
      ans = max(ans, total);
    }
  }
  printf("%d\n", ans);
  return 0;
}
int main(int argc, char* argv[]) {
  ::std::ios::sync_with_stdio(false);
  ::std::cin.tie(0);
  ::std::cout.tie(0);
  solve();
  return 0;
}
