int N = Integer.parseInt(reader.readLine()); //размер списка строк
       int M = Integer.parseInt(reader.readLine()); //размер массива строк

       ArrayList<String> list = new ArrayList<>();


       for(int i=0; i< N; i++) // add strings to list
       {
           list.add(reader.readLine());
       }
       String[] strArr = new String[M];
       for(int i=0; i < M; i++) // temporary save M strings to array
       {                                   // and del M strings from list
           strArr[i] = list.get(i);        //then add this strings

            list.add(strArr[i]);
            list.remove(0);
       }


       for(int i=0; i<list.size();i++)
       {
           System.out.println(list.get(i));

       }