In reply to Sam.

Sam, I believe you should first sort your data
by country polygon;
then you use first.polygon and last.polygon .