#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  int ans = 0;
  bool valid = true;
  int diff = vec[1] - vec[0];
  for (int i = 2; i < n; i++) {
    int cur = vec[i] - vec[i - 1];
    if (cur != diff) {
      valid = false;
      break;
    }
  }
  if (valid) {
    cout << vec[n - 1] + diff << endl;
  } else {
    cout << vec[n - 1] << endl;
  }
}
