#include<bits/stdc++.h>
#include <complex>
#define Write freopen("out.txt","w",stdout)
#define Read freopen("in.txt","r",stdin)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sl(a) scanf("%lld",&a)
#define sll(a,b) scanf("%lld %lld",&a,&b)
#define slll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define m_p make_pair
#define ll long long
#define lim 10000000
#define mod 100007
#define mx 100004
using namespace std;
#define MAX_N 200005 // second approach: O(n log n)
string T;
int n; // the length of input string
int RA[MAX_N], tempRA[MAX_N]; // rank array and temporary rank array
int SA[MAX_N], tempSA[MAX_N]; // suffix array and temporary suffix array
int c[MAX_N]; // for counting/radix sort
void countingSort(int k) // O(n)
{
int i, sum, maxi = max(300, n); // up to 255 ASCII chars or length of n
memset(c, 0, sizeof c); // clear frequency table
for (i = 0; i < n; i++) // count the frequency of each integer rank
{
c[i + k < n ? RA[i + k] : 0]++;
}
for (i = sum = 0; i < maxi; i++)
{
int t = c[i];
c[i] = sum;
sum += t;
}
for (i = 0; i < n; i++) // shuffle the suffix array if necessary
{
tempSA[c[SA[i]+k < n ? RA[SA[i]+k] : 0]++] = SA[i];
}
for (i = 0; i < n; i++) // update the suffix array SA
{
SA[i] = tempSA[i];
}
}
void suffixarray() // this version can go up to 100000 characters
{
n=T.size();
int i, k, r;
for (i = 0; i < n; i++) RA[i] = T[i]; // initial rankings
for (i = 0; i < n; i++) SA[i] = i; //initial SA: {0, 1, 2, ..., n-1}
for (k = 1; k < n; k <<= 1) // repeat sorting process log n times
{
countingSort(k); //actually radix sort:sort based on the second item
countingSort(0); // then (stable) sort based on the first item
tempRA[SA[0]] = r = 0; // re-ranking; start from rank r = 0
// compare adjacent suffixes
for (i = 1; i < n; i++)
{
// if same pair => same rank r; otherwise,increase r
tempRA[SA[i]] = (RA[SA[i]] == RA[SA[i-1]] && RA[SA[i]+k] == RA[SA[i-1]+k]) ? r : ++r;
}
for (i = 0; i < n; i++) // update the rank array RA
{
RA[i] = tempRA[i];
}
if (RA[SA[n-1]] == n-1) break; // nice optimization trick
}
}
int main()
{
cin>>T;
int cnt=0;
for(int i=0;i<T.size();i++)
{
if(T[i]==T[0]) cnt++;
}
if(cnt==T.size()){
cout<<"0"<<endl;
return 0;
}
int len=T.size();
T=T+T;
T+="$";
suffixarray();
for(int i=0;i<T.size()-1;i++)
{
if(SA[i]<len){
cout<<SA[i]<<endl;
return 0;
}
}
///cout<<ans<<endl;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGUgPGNvbXBsZXg+CgojZGVmaW5lIFdyaXRlIGZyZW9wZW4oIm91dC50eHQiLCJ3IixzdGRvdXQpCiNkZWZpbmUgUmVhZCBmcmVvcGVuKCJpbi50eHQiLCJyIixzdGRpbikKCiNkZWZpbmUgc2koYSkgICAgICAgICAgIHNjYW5mKCIlZCIsJmEpCiNkZWZpbmUgc2lpKGEsYikgICAgICAgIHNjYW5mKCIlZCAlZCIsJmEsJmIpCiNkZWZpbmUgc2lpaShhLGIsYykgICAgIHNjYW5mKCIlZCAlZCAlZCIsJmEsJmIsJmMpCgojZGVmaW5lIHNsKGEpICAgICAgICAgICBzY2FuZigiJWxsZCIsJmEpCiNkZWZpbmUgc2xsKGEsYikgICAgICAgIHNjYW5mKCIlbGxkICVsbGQiLCZhLCZiKQojZGVmaW5lIHNsbGwoYSxiLGMpICAgICBzY2FuZigiJWxsZCAlbGxkICVsbGQiLCZhLCZiLCZjKQoKI2RlZmluZSBtX3AgbWFrZV9wYWlyCiNkZWZpbmUgbGwgbG9uZyBsb25nCgojZGVmaW5lIGxpbSAxMDAwMDAwMAojZGVmaW5lIG1vZCAxMDAwMDcKI2RlZmluZSBteCAxMDAwMDQKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBNQVhfTiAyMDAwMDUgLy8gc2Vjb25kIGFwcHJvYWNoOiBPKG4gbG9nIG4pCnN0cmlu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