Output looks ok. I read from keyboard N strings then add M at the end then remove first four.
package pl.codegym.task.task07.task0720;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
/*
Przestawiono w samą porę
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(reader.readLine());
int M = Integer.parseInt(reader.readLine());
ArrayList<String> lista = new ArrayList<String>();
for (int i = 0; i < N; i++)
{
lista.add(reader.readLine());
}
for (int i = 0; i < M; i++)
{
lista.add(lista.get(i));
}
for (int i = 0; i < M; i++)
{
lista.remove(lista.get(i));
}
for (String s : lista) {
System.out.println(s);
}
}
}