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