#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int f1[N], f2[N], f3[N];
int main() {
  string s;
  int n, ans = 0;
  cin >> s;
  n = s.length();
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == 'a') {
      for (int j = i - 1; ~j; j--) {
        f1[i] = max(f1[i], f1[j] + 1);
        f3[i] = max(f3[i], max(f3[j] + 1, f2[j] + 1));
      }
      f2[i] = 0;
    } else {
      f1[i] = f3[i] = 0;
      for (int j = i - 1; ~j; j--)
        f2[i] = max(f2[i], max(f1[j] + 1, f2[j] + 1));
    }
    ans = max(ans, max(f3[i], f2[i]));
  }
  cout << ans << endl;
  return 0;
}
