#include <bits/stdc++.h>
using namespace std;
void File() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
void IO() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  IO();
  string s;
  cin >> s;
  if (s.size() == 1) {
    cout << 1 << endl;
    return 0;
  }
  int a[5500], b[5500];
  for (int i = 0; i < 5500; ++i) a[i] = b[i] = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'a')
      a[i] = 1;
    else
      b[i] = 1;
  }
  for (int i = 1; i <= s.size(); ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }
  int ans = INT_MIN;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = i + 1; j < s.size(); ++j) {
      ans = max(ans, a[i] + (b[j] - (i - 1 < 0 ? 0 : b[i - 1])) +
                         ((a[s.size() - 1] - (j - 1 < 0 ? 0 : a[j - 1]))));
    }
  }
  cout << ans << endl;
  return 0;
}
