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