Brute force solution for small input