#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
// #define debug
using ll = long long;
void solve()
{
    string s;
    cin >> s;
    for(auto &i:s)
    {
        if(i>='A'&&i<='Z')
        {
            i += 32;
        }
    }
    string str = "bob!" + s;
    vector<int> pi(str.size(),0);
    for(int i=1;i<str.size();i++)
    {
        int len = pi[i - 1];
        while(len !=0&&str[i]!=str[len])
        {
            len = pi[len - 1];
        }
        if(str[i]==str[len])
        {
            pi[i] = len + 1;
            if(pi[i]==3)
            {
                cout << i - 3 * 2;
                return;
            }
        }
    }
    cout << -1;
    return;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n = 1;
    while (n--)
        solve();
    return 0;
}