#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, y, tow, b = 0, x;
  cin >> n >> x >> y;
  tow = y - x;
  for (i = 2; i < n; i++) {
    cin >> x;
    if (x != y + tow) b = 1;
    y = x;
  }
  if (b != 0)
    cout << y;
  else
    cout << y + tow;
}
