#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, res = 0, prev, t, sum, tmp;
  cin >> n;
  cin >> prev;
  bool ok = true;
  for (int i = 1; i < n; i++) {
    cin >> t;
    sum = t - prev;
    if (i != 1 && tmp != sum) ok = false;
    tmp = sum;
    prev = t;
  }
  cout << (ok ? t + sum : t) << endl;
  return 0;
}
