Overflow-Proof Buffer
Perl, 37 bytes

35 bytes of code + 2 bytes for -lp flags.

splice@F,1+&lt;&gt;%(@F||1),0,$_}{$_="@F"


Try it online!

The implementation is quite straight forward, splice inserts in array @F at index 1+&lt;&gt;%(@F||1) (note that @F||1 handles the case of the array being empty).

Just a few words about the (seemingly) unmatched braces }{ (because I had a comment about it, and I think it's quite weird for people who don't know Perl), and it's a quite common trick in Perl golfings:
-p flag surrounds the code with (roughly) while(&lt;&gt;){ CODE } continue { print }, (the continue is executed after each iteration). So with those unmatched }{, I change my code to while(&lt;&gt;) { CODE}{ } continue { print }. So it creates an empty block right after my code (but that's not a problem), and the continue is executed only once, after the while (ie. when the all the input has been read).