#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, res = 0, i, t, t2 = 1;
  cin >> n;
  vector<int> v;
  for (long long int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    v.push_back(a);
  };
  t = v[1] - v[0];
  for (i = 2; i < n; i++) {
    if ((v[i] - v[i - 1]) != t) t2 = 0;
  }
  if (t2 == 0)
    cout << v[n - 1] << endl;
  else
    cout << (v[n - 1] + t) << endl;
}
