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