#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;
}