#include <bits/stdc++.h>
using namespace std;
long long tests;
long long n, a[1000256];
bool ok;
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i > 2 && a[i] != a[i - 1] + (a[2] - a[1])) ok = 1;
  }
  if (ok == 1)
    cout << a[n];
  else
    cout << a[n] + (a[2] - a[1]);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  solve();
}
