#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897;
struct node {
  int x;
  int y;
} p[100007];
int ans = 0;
int main() {
  string str;
  cin >> str;
  int n = str.length();
  for (int i = 0; i < n; i++) {
    if (str[i] == 'a') {
      p[i].x = p[i - 1].x + 1;
      p[i].y = p[i - 1].y;
    } else {
      p[i].x = p[i - 1].x;
      p[i].y = p[i - 1].y + 1;
    }
  }
  for (int i = 0; i < n; i++) {
    ans = max(ans, p[i].x + (p[n - 1].y - p[i].y));
    ans = max(ans, p[i].y + p[n - 1].x - p[i].x);
    for (int j = i + 1; j < n; j++)
      ans = max(ans, p[i].x + p[n - 1].x - p[j - 1].x + p[j - 1].y - p[i].y);
  }
  cout << ans << "\n";
  return 0;
}
