#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
long long mod(long long x) { return ((x % M + M) % M); }
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
long long per(long long a, long long b) {
  while (a >= b) a = a - b;
  return a;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (auto &it : (v)) cin >> it;
  long long cd = v[1] - v[0];
  bool x = true;
  for (long long i = (2); i < (n); ++i) {
    if (v[i] - v[i - 1] != cd) {
      x = false;
      break;
    }
  }
  if (x) {
    long long ans = v[n - 1] + cd;
    cout << ans << '\n';
  } else
    cout << v[n - 1] << '\n';
}
signed main() {
  cout.precision(10);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
