#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string s;
  cin >> s;
  int n = s.size();
  int x = 0, y = 0, z = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'a') {
      x++;
      z++;
    } else
      y++;
    x = max(x, y);
    y = max(y, z);
  }
  cout << x;
  return 0;
}
