#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(12);
  string s;
  cin >> s;
  ;
  int n = s.size();
  vector<int> ac(n + 1), bc(n + 1);
  for (int i = 1; i <= n; i++) {
    ac[i] = ac[i - 1];
    if (s[i - 1] == 'a') ac[i]++;
    bc[i] = bc[i - 1];
    if (s[i - 1] == 'b') bc[i]++;
  }
  int result = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      result = max(result, ac[i] + bc[j] - bc[i] + ac[n] - ac[j]);
    }
  }
  cout << result << endl;
}
