#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
using namespace std;
const int MX = 1e9 + 1;
const int Imp = -1;
const int N = 1e6 + 5;
const int M = 1e5 + 5;
const int INF = 1e18 + 1;
long long mx = -1, ans, sum, cnt, mn = INF;
bool ok, ok1;
long long mp[8];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  int a[n];
  cin >> a[0] >> a[1];
  int d = a[1] - a[0];
  for (int i = 2; i < n; ++i) {
    cin >> a[i];
    if (ok == 0) {
      if (a[i] - a[i - 1] != d) {
        ok = 1;
      }
    }
  }
  if (ok == 1) {
    cout << a[n - 1];
  } else {
    cout << a[n - 1] + d;
  }
}
