You can make it simpler:
l:0;.Q.fs[{if[x~l;:];-1 l::x}each]`:input
or if you have memory: -1 distinct read0`:input
...or if you want to use k: -1@?0:`:input