#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  string s;
  cin >> s;
  long long f = 1, ans = 0;
  while (f == 1) {
    f = 0;
    for (int i = 0; i < s.length() - 1; i++) {
      if (s[i] == 'a' && s[i + 1] != 'a') {
        s.erase(i + 1, 1);
        f = 1;
      } else if (s[i + 1] == 'a' && s[i] != 'a') {
        s.erase(i, 1);
        f = 1;
      }
    }
    ans++;
  }
  cout << ans - 1;
  return 0;
}
