#import pdb; pdb.set_trace()

def main():
    n = int(raw_input())
    s = []
    for i in range(n):
        s.append(int(raw_input()))
    m = int(raw_input())
    
    dq = [[float("inf") for i in range(n)] for j in range(n)]
    for i in range(m):
        (a,b,c) = map(int, raw_input().split())
        dq[a][b] = c
        dq[b][a] = c
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if dq[i][j] > dq[j][k] + dq[i][k]:
                    dq[i][j] = dq[j][k] + dq[i][k]
                    dq[j][i] = dq[i][j]
    minimum = float("inf")
    
    for i in xrange(1, n - 1):
        for j in xrange(1, n - 1):
            if i == j:
                continue
            
            minimum = min(minimum, dq[0][i] + dq[i][j] + dq[j][n - 1] + s[i] + s[j])
    
    print minimum
    
if __name__ == '__main__':
    main()