#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int l, r;
  vector<int> prefix_a(n);
  if (s[0] == 'a')
    prefix_a[0] = 1;
  else
    prefix_a[0] = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] == 'a')
      prefix_a[i] = prefix_a[i - 1] + 1;
    else
      prefix_a[i] = prefix_a[i - 1];
  }
  prefix_a.insert(prefix_a.begin(), 0);
  int min = INT_MAX;
  for (l = 0; l <= n; l++) {
    for (r = l; r <= n; r++) {
      int part1st_cnt_b = l - prefix_a[l];
      int part2nd_cnt_a = prefix_a[r] - prefix_a[l];
      int part3rd_cnt_b = (n - r) - (prefix_a[n] - prefix_a[r]);
      int val = (part1st_cnt_b) + (part2nd_cnt_a) + (part3rd_cnt_b);
      if (val < min) min = val;
    }
  }
  cout << n - min;
  return 0;
}
