#include <bits/stdc++.h>
using namespace std;
const long long max_n = 1e5 + 20;
long long n, m, k, mn = 1e9 + 20, tmp, tmp2, cnt;
long long a[max_n], b[max_n];
long long alert, v, mark[max_n], e[max_n];
string s[max_n];
long long ans;
int32_t main() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  tmp = a[0] - a[1];
  for (long long i = 1; i < n - 1; i++) {
    if (a[i] - a[i + 1] != tmp) {
      cout << a[n - 1] << endl;
      return 0;
    }
  }
  cout << a[n - 1] - tmp;
  return 0;
}
