public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<String> list = new ArrayList<String>();
        int N = Integer.parseInt(reader.readLine());
        int M = Integer.parseInt(reader.readLine());

        for (int i = 0; i < N; i++) {
            list.add(reader.readLine()); }

        for (int i = 0; i < M; i++) {
            list.remove(list.size()-1); }

        for (int i = 0; i < M; i++) {
            String a  = list.get(i);
            list.add(a); }

        for(String b : list)
            System.out.println(b);

    }
}