import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { long t = System.currentTimeMillis(); new Main().run(); System.err.println(System.currentTimeMillis() - t); } void run() { Scanner sc = new Scanner(System.in); int N=sc.nextInt(); int M=sc.nextInt(); int[] pay=new int[N]; String[] l=new String[M]; int p=0,dir=1; for(int i=0;i