#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int(i) = (0); (i) < (n); (i)++) {
    cin >> a[i];
  }
  int d = a[1] - a[0];
  bool was = false;
  for (int(i) = (0); (i) < (n - 1); (i)++) {
    if (a[i + 1] - a[i] != d) {
      was = true;
      break;
    }
  }
  if (was) {
    d = 0;
  }
  int ans = a.back() + d;
  cout << ans << endl;
  return 0;
}
