#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int a = 0, b = 0, c = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'a')
      a++, c = max(b + 1, c + 1);
    else
      b = max(b + 1, a + 1);
  }
  cout << max(b, c);
}
