Project Euler 523 - First Sort I

Official link: https://projecteuler.net/problem=523