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