Program cog1237;
Var
L,R,H,K:Array[0..1010]Of Longint;
A:Array[0..1010]Of Char;
N,M,S,I,J,T:Longint;
Begin
Assign(Input,'jademoon.in');
Assign(Output,'jademoon.out');
Reset(Input);
Rewrite(Output);
Readln(N,M);
While Eoln Do Readln;
Fillchar(H,Sizeof(H),0);
S:=0;
Repeat
T:=0;
K[0]:=0;
For I:=1 To M Do
Begin
Read(A[I],A[I+1]);
If A[I]='F'
Then Begin
Inc(H[I]);
While (T<>0) And (H[K[T]]>=H[I]) Do Dec(T);
L[I]:=K[T];
Inc(T);
K[T]:=I;
End
Else Begin
H[I]:=0;
While (T<>0) And (H[K[T]]>=H[I]) Do Dec(T);
Inc(T);
K[T]:=I;
L[I]:=I;
End;
End;
T:=0;
K[0]:=M+1;
For I:=M Downto 1 Do
If A[I]='F'
Then Begin
While (T<>0) And (H[K[T]]>=H[I]) Do Dec(T);
R[I]:=K[T];
Inc(T);
K[T]:=I;
If S<(R[I]-L[I]-1)*H[I] Then S:=(R[I]-L[I]-1)*H[I];
End
Else Begin
While (T<>0) And (H[K[T]]>=H[I]) Do Dec(T);
Inc(T);
K[T]:=I;
R[I]:=I;
End;
Readln;
Dec(N);
Until N=0;
Writeln(S*3);
Close(Input);
Close(Output);
End.