public Integer popAt(int index) {
        if (stacks.isEmpty())
            throw new IllegalStateException("Stacks are empty!");
        if (index < 0 || index >= stacks.size())
            throw new IllegalArgumentException("Invalid index!");
        int item = stacks.get(index).pop();
        for (int i = index; i < stacks.size() - 1; ++i) {
            Stack<Integer> curr = stacks.get(i);
            Stack<Integer> next = stacks.get(i + 1);
            curr.push(next.remove(0));
        }
        if (stacks.getLast().isEmpty())
            stacks.removeLast();
        return item;
    }