#include <bits/stdc++.h>
using namespace std;
int c = 0;
string s;
vector<char> v[3];
int main() {
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'a')
      v[1].push_back(s[i]);
    else
      v[2].push_back(s[i]);
  }
  if (v[1].size() > v[2].size()) {
    cout << s.length() << endl;
    return 0;
  } else {
    c = 0;
    while (v[1].size() <= v[2].size()) {
      v[2].pop_back();
      c++;
    }
  }
  cout << ((s.length()) - c) << endl;
}
