#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, z = 0;
  cin >> n;
  long long a[n + 101];
  set<long long> s;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i < n; i++) {
    s.insert(a[i + 1] - a[i]);
    z = a[i + 1] - a[i];
  }
  if (s.size() == 1) {
    cout << a[n] + z;
    return 0;
  }
  cout << a[n];
}
