#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCnN0cnVjdCBwb2ludHsKCWludCB4LCB5OwoJcG9pbnQoKXsKCQl4ID0gMDsKCQl5ID0gMDsKCX0KCXBvaW50KGludCB4MSxpbnQgeTEpewoJCXg9eDE7CgkJeT15MTsKCX0KCWJvb2wgaXNlcXVhbChwb2ludCZhLCBwb2ludCZiKTsKfW15X3BvaW50OwogCmJvb2wgcG9pbnQ6OmlzZXF1YWwocG9pbnQmYSwgcG9pbnQmYil7CglyZXR1cm4gYS54ID09IGIueCBhbmQgYS55ID09IGIueTsKfSAKIAppbnQgbWFpbigpIHsKCWludCBjb3VudGVyID0gMCwgeCA9IDAsIHkgPSAwLCByZXMgPSAwOwoJY2hhciBjOwoJYm9vbCBzdG9wID0gZmFsc2U7Cgl2ZWN0b3I8cG9pbnQ+IGNvb3IoMSk7Cgl3aGlsZShjaW4gPj4gYyBhbmQgc3RvcCA9PSBmYWxzZSl7CgkJaWYoYyA9PSAnTCcpewoJCQljb3VudGVyID0gKGNvdW50ZXIgKyAxKSU0OwoJCX0KCQllbHNl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