#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long d = a[1] - a[0];
  for (long long i = 2; i < n; i++) {
    if (a[i] - a[i - 1] != d) {
      cout << a[n - 1];
      return;
    }
  }
  cout << a[n - 1] + d;
  return;
}
int main() {
  solve();
  return 0;
}
