#include <iostream>
#include <vector>
using namespace std;
 
struct point{
	int x, y;
	point(){
		x = 0;
		y = 0;
	}
	point(int x1,int y1){
		x=x1;
		y=y1;
	}
	bool isequal(point&a, point&b);
}my_point;
 
bool point::isequal(point&a, point&b){
	return a.x == b.x and a.y == b.y;
} 
 
int main() {
	int counter = 0, x = 0, y = 0, res = 0;
	char c;
	bool stop = false;
	vector<point> coor(1);
	while(cin >> c and stop == false){
		if(c == 'L'){
			counter = (counter + 1)%4;
		}
		else if(c == 'R'){
			counter = ((counter - 1) + 4)%4;
		}
		else{
			if(counter == 0){
				y++;
			}
			else if(counter == 1){
				x--;
			}
			else if(counter == 2){
				y--;
			}
			else{
				x++;
			}
			res++;
			point a(x,y);
			for(int j = 1; j < coor.size();j++){
				if(my_point.isequal(coor[j],a)){
					stop = true;
				}
			}
			coor.push_back(a);
		}
	}
	cout << ((stop == true) ? res : -1);
	return 0;
}