/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ants;
import java.util.PriorityQueue;
/**
*
* @author cteam066
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main
(String[] args
) { java.
util.
Scanner in
= new java.
util.
Scanner(System.
in); int intovepole[] = new int[100001];
int prevodnypole[] = new int[100001];
char charovypole[] = new char[100001];
while (in.hasNextInt()) {
int L = in.nextInt();
int A = in.nextInt();
int maxR = -1;
int maxL = -1;
PriorityQueue<data> fronta = new PriorityQueue<data>();
for (int i = 0; i <= L; ++i) {
prevodnypole[i] = i;
}
for (int i = 0; i < A; ++i) {
int a = in.nextInt();
char c = in.next().charAt(0);
intovepole[i] = a;
charovypole[a] = c;
}
for (int i = 0; i < A; ++i) {
if (charovypole[intovepole[i]] == 'R') {
if (L - intovepole[i] > maxR) {
maxR = L - intovepole[i];
}
for (int j = 0; j < A; ++j) {
if (charovypole[intovepole[j]] == 'L' &&
intovepole[j] > intovepole[i]) {
fronta.add(new data(intovepole[i], intovepole[j], intovepole[j] - intovepole[i]));
}
}
} else if (intovepole[i] > maxL) {
maxL = intovepole[i];
}
}
while (!fronta.isEmpty()) {
data d = fronta.poll();
int temp = prevodnypole[d.i];
prevodnypole[d.i] = prevodnypole[d.j];
prevodnypole[d.j] = temp;
}
System.
out.
print("The last ant will fall down in " + (maxR
> maxL
? maxR
: maxL
) + " seconds - started at ");
if (maxR > maxL) {
System.
out.
println(prevodnypole
[L
- maxR
] + "."); } else if (maxL > maxR) {
System.
out.
println(prevodnypole
[maxL
] + "."); } else {
int min = prevodnypole[L - maxR] < prevodnypole[maxL] ? prevodnypole[L - maxR] : prevodnypole[maxL];
int max = prevodnypole[L - maxR] + prevodnypole[maxL] - min;
System.
out.
println(min
+ " and " + max
+ "."); }
}
}
static class data implements Comparable<data> {
data(int _i, int _j, int _k) {
i = _i;
j = _j;
key = _k;
}
public int compareTo(data arg0) {
return key - arg0.key;
}
public int i, j, key;
}
}