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