I added the "liste.remove(4):" because I had an empty line there that I do not know from where it came
package fr.codegym.task.task07.task0720;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.IOException;
/*
Mélange en temps opportun
*/
public class Solution {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
ArrayList<String> liste = new ArrayList<String>();
for(int i = 0; i < n + 1; i++){
liste.add(scanner.nextLine());
}
for(int i = 0; i < m + 1; i++){
String tampon = liste.get(0);
liste.remove(tampon);
liste.add(tampon);
}
liste.remove(4);
for(int k = 0; k < n; k++){
System.out.println(liste.get(k));
}
}
}