There was a thrilling finish to Stage 3 of the Giro d'Italia as Tim Merlier snatched victory after a bunch sprint.