#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  while (cin >> n) {
    long long arr[1000];
    for (long long i = 1; i <= n; i++) {
      cin >> arr[i];
    }
    long long x1, x2, c, d, cn1 = 0, cnt2 = 0;
    x1 = arr[1] - arr[2];
    for (long long i = 1; i < n; i++) {
      c = arr[i] - arr[i + 1];
      if (c != x1) cn1 = 1;
    }
    if (cn1 == 0 && x1 != 0) {
      if (arr[1] > arr[2])
        cout << arr[n] - x1 << endl;
      else
        cout << arr[n] - x1 << endl;
    } else
      cout << arr[n] << endl;
  }
  return 0;
}
