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