#include <map>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
struct dat{
string cad;
int prof;
dat(string pcad, int pprof)
{
cad = pcad;
prof = pprof;
}
dat()
{
cad = "";
prof = -1;
}
};
class LightSwitchingPuzzle {
public:
map<string, bool> check;
int checkN[1001];
queue<dat> Q;
int minFlips( string state ) {
int n = state.length();
string s1, s2;
for(int i=0;i<n;i++)
{
s1.push_back('Y');
s2.push_back('N');
checkN[i] = 0;
}
if(state == s1)
return 1;
else if(state == s2)
return 0;
else
{
dat Qfront;
string temp;
check[state] = 1;
Q.push(dat(state, 0));
while(!Q.empty())
{
Qfront = Q.front();
Q.pop();
bool can = true;
for(int i=1;i<=n && can;i++)
{
if(checkN[i-1])
continue;
if(Qfront.cad[i-1] == 'Y')
{
string temp = Qfront.cad;
for(int j=i-1;j<n;j+=i)
{
temp[j] = (Qfront.cad[j] == 'Y' ? 'N' : 'Y');
}
if(temp == s2)
return Qfront.prof + 1;
if(!check[temp])
{
check[temp] = 1;
checkN[i-1] = 1;
Q.push(dat(temp, Qfront.prof + 1));
can = false;
break;
}
}
}
}
return -1;
}
}
};
int main() {
LightSwitchingPuzzle obj;
string cad;
cin >> cad;
cout << obj.minFlips(cad) << endl;
return 0;
}
I2luY2x1ZGUgPG1hcD4gCiNpbmNsdWRlIDxjbWF0aD4gCiNpbmNsdWRlIDxjdGltZT4gCiNpbmNsdWRlIDxkZXF1ZT4gCiNpbmNsdWRlIDxxdWV1ZT4gCiNpbmNsdWRlIDxzdGFjaz4gCiNpbmNsdWRlIDxjY3R5cGU+IAojaW5jbHVkZSA8Y3N0ZGlvPiAKI2luY2x1ZGUgPHN0cmluZz4gCiNpbmNsdWRlIDx2ZWN0b3I+IAojaW5jbHVkZSA8Y2xpb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