#include <bits/stdc++.h>
using namespace std;
auto scan = [] {
  static long long a;
  scanf("%lld", &a);
  return a;
};
string s;
long long coun[2][10000] = {0};
int main() {
  string s;
  cin >> s;
  for (long long i = 1; i <= s.size(); ++i) {
    coun[1][i] = coun[1][i - 1] + (s[i - 1] == 'b');
    coun[0][i] = coun[0][i - 1] + (s[i - 1] == 'a');
  }
  long long ans = 0;
  for (long long i = 0; i <= s.size(); ++i) {
    for (long long j = 0; j <= i; ++j) {
      ans = max(ans, coun[0][j] + coun[1][i] - coun[1][j] + coun[0][s.size()] -
                         coun[0][i]);
    }
  }
  cout << ans << '\n';
}
