#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
const int N = 1e4 + 5;
int v[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  set<int> diff;
  for (int i = 2; i <= n; i++) {
    diff.insert(v[i] - v[i - 1]);
  }
  if (diff.size() == 1) {
    cout << v[n] + *(diff.begin());
  } else {
    cout << v[n];
  }
  return 0;
}
