#include <bits/stdc++.h>
using namespace std;
const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int inf = 1061109567;
const long long linf = 3e18;
const double dinf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-6;
long long read() {
  long long t = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    t = t * 10 + ch - '0';
    ch = getchar();
  }
  return t * f;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline long long C(long long n, long long m, long long ans = 1) {
  for (long long i = 0; i < m; i++) ans *= (n - i);
  for (long long i = m; i; i--) ans /= i;
  return ans;
}
inline long long A(long long n, long long m, long long ans = 1) {
  for (long long i = n; i > n - m; i--) ans *= i;
  return ans;
}
extern const int MAXN = 5e5 + 5;
extern const int N = 100;
int n;
map<int, bool> m, t;
int a[MAXN];
int work() {
  n = read();
  for (register int i = (1), I = (n) + 1; i < I; ++i) a[i] = read();
  int r = n;
  while (!m[a[r]] && r) m[a[r]] = 1, r--;
  if (r == 0) return printf("0\n");
  r++;
  int l = 1;
  while (!m[a[l]]) m[a[l]] = 1, l++;
  int ans = r - l;
  for (; r <= n + 1; r++) {
    while (l < r && !m[a[l]]) m[a[l]] = 1, l++;
    ans = min(ans, r - l);
    m[a[r]] = 0;
  }
  write(ans), putchar('\n');
  return 0;
}
int main() {
  std::cin.tie(0);
  ios::sync_with_stdio(false);
  work();
  return 0;
}
