#include <bits/stdc++.h>
using namespace std;
int cntb[50001];
int main() {
  string x;
  cin >> x;
  for (int i = 0; i < x.size(); i++) {
    if (x[i] == 'b') cntb[i]++;
  }
  for (int i = 1; i < x.size(); i++) {
    cntb[i] = cntb[i] + cntb[i - 1];
  }
  int maxlen = 0;
  if (x.size() < 3) {
    cout << x.size() << endl;
    return 0;
  }
  for (int i = 0; i < x.size(); i++) {
    if (x[i] == 'a') maxlen++;
  }
  for (int i = 0; i < x.size(); i++) {
    for (int j = i; j < x.size(); j++) {
      int atorem = cntb[j];
      if (i != 0) atorem -= cntb[i - 1];
      atorem = j - i + 1 - atorem;
      int btorem = 0;
      if (j != x.size() - 1) {
        btorem = cntb[x.size() - 1];
        btorem -= cntb[j + 1];
      }
      if (i != 0) {
        btorem += cntb[i - 1];
      }
      maxlen = max(maxlen, (int)x.size() - atorem - btorem);
    }
  }
  cout << maxlen << endl;
  return 0;
}
