#include <bits/stdc++.h>
using namespace std;
string s;
long long dp[5005][5];
long long fun(int pos, int state) {
  if (state > 2) return -1;
  if (pos >= (int)s.size()) return 0;
  if (dp[pos][state] != -1) return dp[pos][state];
  long long ret = 0;
  if (state == 1) {
    if (s[pos] == 'b') {
      ret = 1 + fun(pos + 1, state);
    } else {
      long long ret1 = 1 + fun(pos + 1, state + 1);
      long long ret2 = fun(pos + 1, state);
      ret = max(ret1, ret2);
    }
  } else {
    if (s[pos] == 'a') {
      ret = 1 + fun(pos + 1, state);
    } else {
      long long ret1 = 1 + fun(pos + 1, state + 1);
      long long ret2 = fun(pos + 1, state);
      ret = max(ret1, ret2);
    }
  }
  dp[pos][state] = ret;
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  long long ans = 0, cnt;
  cin >> s;
  long long sz = (long long)s.size();
  for (int i = 0; i < sz; i++) {
    if (s[i] == 'a')
      ans = max(ans, 1 + fun(i + 1, 0));
    else
      ans = max(ans, 1 + fun(i + 1, 1));
  }
  cout << ans << endl;
}
