from collections import defaultdict

def solve(lst):
    found, total = 0, len(set(lst))
    hist = defaultdict(int)
    l = 0
    ans = len(lst)
    for r in xrange(len(lst)):
        occ = hist[lst[r]] = hist[lst[r]] + 1
        if occ == 1:
            found += 1
        while l <= r and found == total:
            ans = min(ans, r - l + 1)
            occ = hist[lst[l]] = hist[lst[l]] - 1
            if not occ:
                found -= 1
            l += 1
    return ans