from itertools import permutations

def solution(n,weak,dist):
    length = len(weak)
    for i in range(length):
        weak.append(weak[i] + n)
        answer = len(dist) + 1 # 최대 사람 수 보다 하나 많게 설정해서 초기화
        for start in range(length):
            for friends in list(permutations(dist,len(dist))):
                count = 1
                position = weak[start] + friends[count-1]
                for index in range(start, start + length):
                    if position < weak[index]:
                        count += 1
                        if count > len(dist):
                            break
                        position = weak[index] + friends[count - 1]
                answer = min(answer,count)
        if answer > len(dist):
            return -1
        return answer
