#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &A : a) cin >> A;
  pair<int, int> p = {100, 100};
  int mx = 0;
  for (int i = 0; i + 1 < n; i++)
    for (int j = i + 1; j < n; j++) {
      if (a[j] - a[i] < mx) {
        mx = a[j] - a[i];
        p.first = a[i];
        p.second = a[j];
      } else if (a[j] - a[i] == mx) {
        if (p.second < a[j]) {
          p.first = a[i];
          p.second = a[j];
        }
      }
    }
  int x = floor(1000 / p.first);
  cout << 1000 - p.first * x + p.second * x;
  return 0;
}
