#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, val;
  cin >> n;
  int ar[n];
  for (int i = 0; i < n; i++) cin >> ar[i];
  if (n == 2) {
    cout << ar[1] + (ar[1] - ar[0]) << endl;
    return 0;
  }
  for (int i = 0; i < n - 2; i++) {
    if (abs(ar[i] - ar[i + 1]) == abs(ar[i + 1] - ar[i + 2]))
      val = ar[i] - ar[i + 1];
    else {
      cout << ar[n - 1] << endl;
      return 0;
    }
  }
  cout << ar[n - 1] - val << endl;
}
