#include <bits/stdc++.h>
using namespace std;
const long long int mx = 100000;
const long long int m = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string str;
  cin >> str;
  string s = "aba";
  vector<int> a(int(str.size()), 0);
  int count_a = 0;
  vector<int> b(int(str.size()), 0);
  int count_b = 0;
  for (int i = 0; i < int(str.size()); i++) {
    if (str[i] == 'a') {
      count_a++;
      a[i] = count_a;
    } else {
      a[i] = count_a;
    }
  }
  for (int i = 0; i < int(str.size()); i++) {
    if (str[i] == 'b') {
      count_b++;
      b[i] = count_b;
    } else {
      b[i] = count_b;
    }
  }
  int count = 0;
  int count_f = max(count_b, count_a);
  if (int(str.size()) < 3) {
    count_f = int(str.size());
  } else {
    for (int i = 0; i < int(str.size()); i++) {
      for (int j = i; j < int(str.size()); j++) {
        count = a[int(str.size()) - 1] + a[i] - a[j] + b[j] - b[i];
        if (count > count_f) {
          count_f = count;
          if (b[i] > 0 && i == 0) {
            count_f++;
          }
        }
      }
    }
  }
  cout << count_f;
  return 0;
}
