#include <bits/stdc++.h>
using namespace std;
string s;
int n, m;
int dp[3][50005];
int main() {
  while (cin >> s) {
    dp[0][0] = 0;
    dp[1][0] = 0;
    dp[2][0] = 0;
    int l = s.length();
    for (int i = 0; i < l; i++) {
      dp[0][i + 1] = dp[0][i] + (s[i] == 'a');
      dp[1][i + 1] = max(dp[0][i], dp[1][i]) + (s[i] == 'b');
      dp[2][i + 1] = max(max(dp[0][i], dp[1][i]), dp[2][i]) + (s[i] == 'a');
    }
    cout << max(max(dp[0][l], dp[1][l]), dp[2][l]) << endl;
  }
  return 0;
}
