#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int long long n;
  cin >> n;
  int long long x, x1, t = 0;
  cin >> x;
  t = x;
  cin >> x;
  t -= x;
  for (int i = 0; i < n - 2; i++) {
    cin >> x1;
    if (x - x1 == t)
      x = x1;
    else
      t = -100000000000000000ll, x = x1;
  }
  if (t == -100000000000000000ll)
    cout << x << endl;
  else
    cout << x - t << endl;
}
