#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  unordered_map<int, int> a;
  unordered_map<int, int> b;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'a') {
      a[i] = a[i - 1] + 1;
      b[i] = b[i - 1];
    } else {
      b[i] = b[i - 1] + 1;
      a[i] = a[i - 1];
    }
  }
  int max = 0;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size(); j++) {
      int temp = 0;
      temp = a[i - 1] + b[j] - b[i - 1] + a[s.size() - 1] - a[j - 1];
      if (max < temp) {
        max = temp;
      }
    }
  }
  cout << max;
  return 0;
}
