package javaapplication1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Ants {
while ((line = reader.readLine()) != null) {
String[] split
= line.
split(" ");
int len
= Integer.
parseInt(split
[0]); int n
= Integer.
parseInt(split
[1]);
List<Integer> arr = new ArrayList<Integer>();
int max = -1;
int min = len + 1;
int lCount = 0;
for (int i = 0; i < n; i++) {
line = reader.readLine();
split = line.split(" ");
int pos
= Integer.
parseInt(split
[0]);
if (split[1].equals("R")) {
if (pos < min) {
min = pos;
}
} else {
if (pos > max) {
max = pos;
}
lCount++;
}
arr.add(pos);
}
if(max == -1) lCount++;
if(min == len+1) lCount--;
if (min < len - max) {
System.
out.
println("The last ant will fall down in " + (len
- min
) + " seconds - started at " + arr.get(lCount - 1) + ".");
} else if (min > len - max) {
System.
out.
println("The last ant will fall down in " + max
+ " seconds - started at " + arr.get(lCount) + ".");
} else {
System.
out.
println("The last ant will fall down in " + max
+ " seconds - started at " + arr.get(lCount-1)
+ " and "+ arr.get(lCount) + ".");
}
}
reader.readLine();
}
}