line = int(input()) to = line - 1 edge = int(input()) graph = [[0 for i in range(line)]for i in range(line)] for i in range(edge): n, m = map(int, input().split()) graph[n][m] = 1 level = [0] * line marked = [False] * line __________ queue = [0] * line head = 0 tail = 1 while head < tail and not flag: __________ head += 1 for j in range(line): if j != c and graph[c][j] == 1: if j != to and marked[j] == False: queue[tail] = j tail += 1 marked[j] = True level[j] = level[c]+1 elif j == to: __________ flag = True break print(level[-1]-1)