#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1.0);
template <typename T1, typename T2>
void ckmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
void ckmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
  return f ? -x : x;
}
template <typename T>
void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void print(T x, char let) {
  print(x), putchar(let);
}
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
const int maxn = 2000 + 6;
void table() {
  int l = 1, r = 2000;
  long long sum = 0;
  for (int i = (1); i <= (r); i++) {
    for (int j = (i); j <= (r); j++) {
      sum += (j - i + 1);
    }
  }
  cout << sum << '\n';
}
set<int> pre[maxn], suf[maxn];
int a[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = (1); i <= (n); i++) cin >> a[i];
  int ans = n;
  for (int i = (1); i <= (n); i++) {
    set<int> s;
    for (int j = (1); j < (i); j++) s.insert(a[j]);
    for (int j = (n); j >= (i); j--) {
      int sum1 = i - 1;
      int sum2 = n - j;
      if ((int)s.size() == sum1 + sum2) {
        ans = min(ans, n - sum1 - sum2);
      } else
        break;
      s.insert(a[j]);
    }
    if ((int)s.size() == n) ans = 0;
  }
  cout << ans << '\n';
  return 0;
}
