public static void main(String[] args) throws IOException { Scanner sc1 = new Scanner(System.in); ArrayList<String> list = new ArrayList<>(); int N = Integer.parseInt(sc1.nextLine()); int M = Integer.parseInt(sc1.nextLine()); for(int x = 0; x<N; x++) { String w = sc1.nextLine(); list.add(w); } for(int x = 0; x<M; x++) { list.add(list.get(0)); list.remove(0); } for (int k = 0; k < M; k++) { list.remove(0); } } }