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