#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 0;
  string s;
  cin >> s;
  int n = s.size();
  int dp[2][n + 1];
  dp[0][0] = dp[1][0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[0][i] = dp[0][i - 1] + int('b' - s[i - 1]);
    dp[1][i] = dp[1][i - 1] + 1 - int('b' - s[i - 1]);
  }
  for (int i = 0; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      ans = max(ans, dp[0][n] + dp[0][i] + dp[1][j] - dp[0][j] - dp[1][i]);
    }
  }
  cout << ans;
  return 0;
}
