#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T BMOD(T p, T e, T m) {
  T ret = 1;
  while (e) {
    if (e & 1) ret = (ret * p) % m;
    p = (p * p) % m;
    e >>= 1;
  }
  return (T)ret;
}
template <class T>
inline T MODINV(T a, T m) {
  return BMOD(a, m - 2, m);
}
template <class T>
inline T isPrime(T a) {
  for (T i = 2; i <= sqrt(double(a)); i++) {
    if (a % i == 0) {
      return 0;
    }
  }
  return 1;
}
template <class T>
inline T lcm(T a, T b) {
  return (a / __gcd(a, b)) * b;
}
template <class T>
inline T power(T a, T b) {
  return (b == 0) ? 1 : a * power(a, b - 1);
}
template <class T>
inline string toString(T t) {
  stringstream ss;
  ss << t;
  return ss.str();
}
template <class T>
inline long long toLong(T t) {
  stringstream ss;
  ss << t;
  long long ret;
  ss >> ret;
  return ret;
}
template <class T>
inline int toInt(T t) {
  stringstream ss;
  ss << t;
  int ret;
  ss >> ret;
  return ret;
}
template <class T>
inline bool leapYear(T t) {
  if (!(t % (T)400) || (!(t % (T)4) && t % (T)100)) return true;
  return false;
}
string buffer;
int INT() {
  getline(cin, buffer);
  return toInt(buffer);
}
int LONG() {
  getline(cin, buffer);
  return toLong(buffer);
}
const int MX = 200010;
const long long MD = 1e9 + 7;
string s;
int sv[5005][5], l;
int go(int p, int f) {
  if (p >= l) return 0;
  int &ret = sv[p][f];
  if (ret != -1) return ret;
  ret = 0;
  if (f == 0) {
    int fl = 0;
    if (s[p] == 'a') fl = 1;
    ret = max(ret, fl + go(p + 1, f));
    ret = max(ret, fl + go(p + 1, 1));
    ret = max(ret, (!fl) + go(p + 1, 1));
  }
  if (f == 1) {
    int fl = 0;
    if (s[p] == 'b') fl = 1;
    ret = max(ret, fl + go(p + 1, f));
    ret = max(ret, fl + go(p + 1, 2));
    ret = max(ret, (!fl) + go(p + 1, 2));
  }
  if (f == 2) {
    int fl = 0;
    if (s[p] == 'a') fl = 1;
    ret = max(ret, fl + go(p + 1, f));
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s;
  l = s.size();
  memset(sv, -1, sizeof sv);
  int Ans = go(0, 0);
  cout << Ans << endl;
  return 0;
}
