#include <bits/stdc++.h>
using namespace std;
using namespace std;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U>
void _W(const pair<T, U> &x) {
  _W(x.first);
  putchar(' ');
  _W(x.second);
}
void W() {}
int MOD = 1e9 + 7;
void ADD(long long &x, long long v) {
  x = (x + v) % MOD;
  if (x < 0) x += MOD;
}
template <typename T>
inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
template <typename T>
inline unsigned long long bigmod(T a, T b, T m) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0)
    return second(bigmod(a, b / 2, m)) % m;
  else
    return (a % m * bigmod(a, b - 1, m)) % m;
}
template <typename T>
inline double cosAngle(T a, T b, T c) {
  double res = a * a + b * b - c * c;
  res = res / (2 * a * b);
  res = acos(res);
  return res;
}
template <typename T>
inline T power(T base, int po) {
  T res = 1;
  if (base == 0) return 0;
  for (int i = (0); i < (po); i++) res *= base;
  return res;
}
long long int num, arr[2007], res, coun = 0, vis[2007], x, val;
map<long long int, int> mpp;
int main() {
  ios::sync_with_stdio(false);
  cin >> num;
  res = num - 1;
  for (int i = (0); i < (num); i++) {
    cin >> val;
    if (mpp[val] == 0) mpp[val] = i;
    arr[i] = val;
  }
  res = num - 1;
  for (int i = (0); i < (num); i++) {
    coun = 0;
    memset(vis, 0, sizeof(vis));
    for (int j = (0); j < (i); j++) {
      if (vis[mpp[arr[j]]] == 1) {
        coun = 1;
        break;
      }
      vis[mpp[arr[j]]] = 1;
    }
    x = num;
    for (int j = (num)-1; j >= (i); j--) {
      if (vis[mpp[arr[j]]] == 1) {
        break;
      }
      x = j;
      vis[mpp[arr[j]]] = 1;
    }
    if (coun == 0) {
      x = num - (num - x + i);
      res = min(res, x);
    }
  }
  cout << res << endl;
}
