Output satisfies the requirements, but it is not enough to pass the tasks. I will be grateful for any sort of help.
package com.codegym.task.task07.task0720;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
/*
Shuffled just in time
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> strings = new ArrayList<>();
int N = Integer.parseInt(reader.readLine());
int M = Integer.parseInt(reader.readLine());
if (N > M) {
for (int i = 0; i < N; i++) {
strings.add(reader.readLine());
}
for (int i = 0; i < M; i++) {
strings.add(strings.get(i));
strings.remove(0);
i++;
}
for (String s : strings) {
System.out.println(s);
}
}
}
}