#include <bits/stdc++.h>
using namespace std;
int maximum(int a, int b) {
  if (a >= b)
    return a;
  else
    return b;
}
int main() {
  string s;
  cin >> s;
  unsigned int i = 0;
  int aba = 0, ab = 0, a = 0;
  for (i = 0; i < s.length(); i++) {
    if (s[i] == 'a') {
      aba++;
      a++;
    }
    if (s[i] == 'b') ab++;
    aba = maximum(aba, ab);
    ab = maximum(ab, a);
  }
  cout << aba;
  return 0;
}
