#include <bits/stdc++.h>
using namespace std;
const int mx = 8e3;
void run_case(void) {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  int d = x[1] - x[0];
  for (int i = 1; i < n - 1; i++) {
    if (x[i + 1] - x[i] != d) {
      cout << x[n - 1] << endl;
      return;
    }
  }
  cout << x[n - 1] + d << endl;
}
int main(void) {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  run_case();
  return 0;
}
