#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = 1e9 + 21;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
template <typename N>
N gcd(N a, N b) {
  return b ? gcd(b, a % b) : a;
}
void precision(long long pr) {
  cout.precision(pr);
  cout << fixed;
}
const int N = 1e6 + 21;
long long a[N];
int main() {
  long long i, j, k, n;
  cin >> n;
  for ((i) = (int)(0); (i) <= (int)(n - 1); (i)++) cin >> a[i];
  long long x = a[0], y = a[1], d;
  d = a[1] - a[0];
  if (n == 2) {
    cout << a[1] + d << '\n';
    return 0;
  }
  bool sach = true;
  for ((i) = (int)(2); (i) <= (int)(n - 1); (i)++) {
    if (a[i - 1] + d != a[i]) {
      sach = false;
      break;
    }
  }
  if (sach)
    cout << a[0] + (n)*d << '\n';
  else
    cout << a[n - 1] << '\n';
  return 0;
}
