#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, x, m, tmp, k, t, ans = 1e9;
int a[N], b[N], h[N];
string s, p;
map<string, int> pol;
vector<int> nei[N];
bool mark[N];
void read_input() {
  cin >> s;
  n = s.size();
  if (s[0] == 'a')
    a[1] = 1;
  else
    b[1] = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] == 'a') {
      a[i + 1] = a[i] + 1;
      b[i + 1] = b[i];
    } else {
      b[i + 1] = b[i] + 1;
      a[i + 1] = a[i];
    }
  }
}
void solve() {
  for (int i = 0; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      tmp = b[i - 1] + b[n] - b[j] + a[j - 1] - a[i];
      ans = min(ans, tmp);
    }
  }
  cout << n - ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  read_input();
  solve();
  return 0;
}
