#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  int numbers[n];
  for (int i = 0; i < n; i++) {
    cin >> numbers[i];
  }
  int average = numbers[0] - numbers[1];
  for (int j = 0; j < n - 1; j++) {
    int temp = numbers[j] - numbers[j + 1];
    if (temp != average) {
      cout << numbers[n - 1];
      return 0;
    }
  }
  cout << numbers[n - 1] - average;
  return 0;
}
