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