#include <bits/stdc++.h>
using namespace std;
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("main.in", "r"))
    freopen("main.in", "r", stdin);
  else if (fopen("something"
                 ".inp",
                 "r"))
    freopen(
        "something"
        ".inp",
        "r", stdin),
        freopen(
            "something"
            ".out",
            "w", stdout);
  string s;
  int cnt0 = 0, cnt1 = 0;
  cin >> s;
  for (int i = 0; i < (int)s.size(); i++)
    if (s[i] == 'a')
      cnt0++;
    else
      cnt1++;
  if (cnt1 < cnt0)
    cout << s.size();
  else {
    cout << s.size() - (cnt1 - cnt0 + 1);
  }
  return 0;
}
