#include <bits/stdc++.h>
using namespace std;
int main() {
  string xxx;
  cin >> xxx;
  int r8m = 0;
  vector<int> sumsa;
  vector<int> sumsb;
  for (int i = 0; i < xxx.size(); i++) {
    if (xxx[i] == 'a') {
      r8m++;
    }
    sumsa.push_back(r8m);
  }
  r8m = 0;
  for (int i = 0; i < xxx.size(); i++) {
    if (xxx[i] == 'b') {
      r8m++;
    }
    sumsb.push_back(r8m);
  }
  int maxx = 0, suma = 0, sumb = 0;
  if (sumsa.back() == 0) {
    maxx = sumsb.back();
  } else if (sumsb.back() == 0) {
    maxx = sumsa.back();
  } else {
    for (int i = 0; i < sumsa.size(); i++) {
      suma = sumsa[i];
      for (int j = i; j < sumsb.size(); j++) {
        sumb = sumsb[j] - sumsb[i];
        maxx = max(maxx, (suma + sumb + sumsa.back() - sumsa[j]));
      }
    }
    for (int i = 0; i < sumsb.size(); i++) {
      sumb = sumsb[i];
      for (int j = i; j < sumsa.size(); j++) {
        suma = sumsa[j] - sumsa[i];
        maxx = max(maxx, (suma + sumb + sumsa.back() - sumsa[j]));
      }
    }
  }
  cout << maxx << endl;
}
