#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  bool flag = true;
  int arr[10000];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int dif = arr[1] - arr[0];
  for (int i = 1; i < n; i++) {
    if (arr[i] - arr[i - 1] != dif) {
      flag = false;
      break;
    }
  }
  if (flag)
    cout << arr[n - 1] + dif;
  else
    cout << arr[n - 1];
}
