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