from collections import defaultdict from heapq import heappop, heappush N = int(input()) stopCost = [int(input()) for _ in range(N)] edges = [[] for _ in range(N)] M = int(input()) for _ in range(M): fr, to, cost = map(int, input().split()) edges[fr].append((to, cost)) edges[to].append((fr, cost)) minDist = defaultdict(lambda : float('inf')) que = [((0, 0, 0, set((0, N - 1))))] while que: now, cnt, d, stop = heappop(que) if minDist[(now, cnt, now in stop)] <= d: continue minDist[(now, cnt, now in stop)] = d if not now in stop and cnt < 2: que.append((now, cnt + 1, d + stopCost[now], stop.copy() | set((now,)))) for to, cost in edges[now]: heappush(que, (to, cnt, d + cost, stop.copy())) ans = minDist[(N - 1, 2, True)] print(ans)