#include <bits/stdc++.h>
using namespace std;
char s[5005];
int main() {
  cin >> s;
  long a = 0, ab = 0, aba = 0;
  for (int i = 0; s[i] != 0; ++i) {
    if (s[i] == 'a') {
      ++a;
      ++aba;
    } else
      ++ab;
    aba = max(ab, aba);
    ab = max(a, ab);
  }
  cout << aba;
  return 0;
}
