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