#include <bits/stdc++.h>
using namespace std;
const int N = (int)250000, mdt = 1e7, limit = 1e8;
const long double eps = 1e-9, eps1 = 1e-20, PI = 3.14159265358979323846264338,
                  OOO = 1e100L, lim = sqrt(1e9 + 100);
const long long OO = 1e18 * 8, mod = 1e9 + 7, md = 4294967291;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  int a[1000], n, d;
  bool c = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i > 1) c &= (a[i] - a[i - 1] == a[1] - a[0]);
  }
  d = a[1] - a[0];
  cout << a[n - 1] + c * d;
  return 0;
}
