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