#include <bits/stdc++.h>
using namespace std;
int v[1000005];
int main() {
  int n, m, i, first, second, lastdif = -0x3f3f3f3f;
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> v[i];
  for (i = 2; i <= n; ++i) {
    if (v[i] - v[i - 1] != lastdif && lastdif != -0x3f3f3f3f) {
      cout << v[n];
      return 0;
      ;
    }
    lastdif = v[i] - v[i - 1];
  }
  cout << v[n] + lastdif;
  return 0;
}
