#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e12;
const long long mod = 1e9 + 7;
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
const long long MAXN = 1000 * 1000 + 10;
const long long N = 1000 * 100 + 10;
long long a[N];
int main() {
  faster();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int i = 1;
  int d = a[1] - a[0];
  int f = 1;
  while (i < n) {
    if (a[i] - a[i - 1] == d)
      i++;
    else {
      i++;
      f = 0;
    }
  }
  if (f)
    cout << a[n - 1] + d << endl;
  else
    cout << a[n - 1] << endl;
}
