//Bismillahir Rahmanir Rahim
/******Harun Or Rashid******/
/***********Template Starts Here***********/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cassert>
#include<string>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
#define MEM(a,b) memset(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)>(b)?(b):(a))
#define ABS(a) ((a)>0? (a):(-(a)))
#define SQ(a) ((a)*(a))
#define SZ(a) (int)a.size()
#define FORN(i,n) for(i=1;i<=n;i++)
#define FORAB(i,a,b) for(i=a;i<=b;i++)
#define ALL(V) V.begin(),V.end()
#define pb(a) push_back(a)
#define pr(a) cout<<a<<endl
#define SQR(a) ((a)*(a))
#define pf printf
#define sf scanf
#define mp make_pair
#define swap(a,b) (a ^= b, b ^= a, a ^= b)
#define PI acos(-1)
#define x first
#define y second
#define eps 1e-7
typedef int D;
typedef long long int LLD;
typedef unsigned long long int LLU;
typedef vector<D> VI;
typedef set<D> SI;
typedef vector<D>::iterator Viti;
/***********Template Ends Here***********/
int gcd(int a,int b)
{
if(b==0) return a;
return gcd(b,a%b);
}
int lcm(int a,int b)
{
return a*(b/gcd(a,b));
}
int main()
{
char str[21];
int i,cnt,ans;
while(1)
{
cin>>str;
if(str[0]=='*') break;
vector<int>tocheak;
vector<int>tocount;
for(i=0; str[i] ; i++)
{
if(str[i]=='N') tocheak.pb(i+1);
else tocount.pb(i+1);
}
if(tocount.size())
{
cnt=tocount[0];
for(i=1; i<tocount.size(); i++)
cnt=lcm(cnt,tocount[i]);
ans=cnt;
for(i=0; i<tocheak.size(); i++)
{
if(cnt%tocheak[i]==0)
{
ans=-1;
break;
}
}
cout<<ans<<endl;
}
else cout<<-1<<endl;
}
return 0;
}
Ly9CaXNtaWxsYWhpciBSYWhtYW5pciBSYWhpbQovKioqKioqSGFydW4gT3IgUmFz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EsYikgKGEgXj0gYiwgYiBePSBhLCBhIF49IGIpCiNkZWZpbmUgUEkgYWNvcygtMSkKI2RlZmluZSB4IGZpcnN0CiNkZWZpbmUgeSBzZWNvbmQKI2RlZmluZSBlcHMgMWUtNwoKdHlwZWRlZiBpbnQgRDsKdHlwZWRlZiBsb25nIGxvbmcgaW50IExMRDsKdHlwZWRlZiB1bnNpZ25lZCBsb25nIGxvbmcgaW50IExMVTsKdHlwZWRlZiB2ZWN0b3I8RD4gVkk7CnR5cGVkZWYgc2V0PEQ+IFNJOwp0eXBlZGVmIHZlY3RvcjxEPjo6aXRlcmF0b3IgVml0aTsKCi8qKioqKioqKioqKlRlbXBsYXRlIEVuZHMgSGVyZSoqKioqKioqKioqLwoKaW50IGdjZChpbnQgYSxpbnQgYikKewogICAgaWYoYj09MCkgcmV0dXJuIGE7CiAgICByZXR1cm4gZ2NkKGIsYSViKTsKfQoKaW50IGxjbShpbnQgYSxpbnQgYikKewogICAgcmV0dXJuIGEqKGIvZ2NkKGEsYikpOwp9CgppbnQgbWFpbigpCnsKICAgIGNoYXIgc3RyWzIxXTsKICAgIGludCBpLGNudCxhbnM7CiAgICB3aGlsZSgxKQogICAgewogICAgICAgIGNpbj4+c3RyOwogICAgICAgIGlmKHN0clswXT09JyonKSBicmVhazsKICAgICAgICB2ZWN0b3I8aW50PnRvY2hlYWs7CiAgICAgICAgdmVjdG9yPGludD50b2NvdW50OwogICAgICAgIGZvcihpPTA7IHN0cltpXSA7IGkrKykKICAgICAgICB7CiAgICAgICAgICAgIGlmKHN0cltpXT09J04nKSB0b2NoZWFrLnBiKGkrMSk7CiAgICAgICAgICAgIGVsc2UgdG9jb3VudC5wYihpKzEpOwogICAgICAgIH0KICAgICAgICBpZih0b2NvdW50LnNpemUoKSkKICAgICAgICB7CiAgICAgICAgICAgIGNudD10b2NvdW50WzBdOwogICAgICAgICAgICBmb3IoaT0xOyBpPHRvY291bnQuc2l6ZSgpOyBpKyspCiAgICAgICAgICAgICAgICBjbnQ9bGNtKGNudCx0b2NvdW50W2ldKTsKICAgICAgICAgICAgYW5zPWNudDsKICAgICAgICAgICAgZm9yKGk9MDsgaTx0b2NoZWFrLnNpemUoKTsgaSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZihjbnQldG9jaGVha1tpXT09MCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBhbnM9LTE7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY291dDw8YW5zPDxlbmRsOwogICAgICAgIH0KICAgICAgICBlbHNlIGNvdXQ8PC0xPDxlbmRsOwogICAgfQogICAgcmV0dXJuIDA7Cn0KCg==