# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# https://www.hackerrank.com/challenges/minimum-distances/problem

# +
# #!/bin/python3

import math
import os
import random
import re
import sys

# Complete the minimumDistances function below.
def minimumDistances(a):
    _min = len(a)
    if len(a)==len(set(a)):
        return -1
    for i in range(len(a)):
        for j in range(len(a)):
            if a[i]==a[j] and i!=j:
                _min = min(_min, abs(i-j))              
    return _min
    

if __name__ == '__main__':
    
    n = int(input())

    a = list(map(int, input().rstrip().split()))

    result = minimumDistances(a)
    
    print (result)

# -



StarcoderdataJupyterScriptsDedupFiltered