#include <bits/stdc++.h>
using namespace std;
int numa[5000], numb[5000];
int main() {
  int res = 0;
  string t;
  cin >> t;
  int l = t.length();
  numa[0] = (t[0] == 'a');
  numb[0] = (t[0] == 'b');
  for (int i = 1; i < l; ++i) {
    numa[i] = numa[i - 1] + (t[i] == 'a');
    numb[i] = numb[i - 1] + (t[i] == 'b');
  }
  for (int i = 0; i < l; ++i)
    for (int j = i; j < l; ++j)
      res = max(res,
                numa[i] + numb[j] - (i != 0) * numb[i] + numa[l - 1] - numa[j]);
  cout << res;
}
