#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[21],b[21];
ll gcd(ll a,ll b)
{
if(!b)return a;
return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a*b/gcd(a,b);
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
string s;
while(cin>>s&&s!="*")
{
for(int i=0;i<21;i++) a[i]=0,b[i]=0;
ll l=s.length(),apos=0,bpos=0;
for(ll i=0;i<l;i++)
{
if(s[i]=='Y')
{
a[apos++]=i+1;
}
else
{
b[bpos++]=i+1;
}
}
ll gbs=lcm(a[0],a[1]);
for(ll i=2;i<apos;i++)gbs=lcm(gbs,a[i]);
for(ll i=0;i<bpos;i++)
{
if(gbs%b[i]==0)
{
gbs=-1;
break;
}
}
cout<<gbs<<endl;
}
return 0;
}