#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int prefA[n + 1], prefB[n + 1];
  memset(prefA, 0, sizeof prefA);
  memset(prefB, 0, sizeof prefB);
  for (int i = 1; i <= n; i++)
    if (s[i - 1] == 'a')
      prefA[i] = prefA[i - 1] + 1;
    else
      prefA[i] = prefA[i - 1];
  for (int i = 1; i <= n; i++)
    if (s[i - 1] == 'b')
      prefB[i] = prefB[i - 1] + 1;
    else
      prefB[i] = prefB[i - 1];
  int best = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      int p = prefA[i] + (prefB[j] - prefB[i - 1]) + (prefA[n] - prefA[j]);
      best = max(p, best);
    }
  }
  cout << best;
  return 0;
}
