#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(false);
  string str;
  cin >> str;
  long long n = str.size();
  vector<long long> dp1(n);
  dp1[0] = (str[0] == 'a');
  for (int i = 1; i < int(n); ++i) {
    dp1[i] = dp1[i - 1] + (str[i] == 'a');
  }
  vector<long long> dp2(n);
  dp2[0] = 1;
  for (int i = 1; i < int(n); ++i) {
    dp2[i] = max(dp1[i], dp2[i - 1] + (str[i] == 'b'));
  }
  vector<long long> dp3(n);
  dp3[0] = 1;
  for (int i = 1; i < int(n); ++i) {
    dp3[i] = max(dp2[i], dp3[i - 1] + (str[i] == 'a'));
  }
  cout << dp3[n - 1] << endl;
}
