#include <bits/stdc++.h>
using namespace std;
typedef priority_queue<pair<int, int>, vector<pair<int, int> >,
                       greater<pair<int, int> > >
    pq;
long long mod = 1000 * 1000 * 1000 + 7;
int n;
int ans;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  ;
  int n;
  bool b = true;
  cin >> n;
  vector<int> v(n);
  for (int i = (0); i < (n); i++) cin >> v[i];
  int d = v[1] - v[0];
  for (int i = (1); i < (n); i++) {
    if (v[i] - v[i - 1] != d) {
      b = false;
      break;
    }
  }
  if (!b) {
    cout << v[n - 1];
    return 0;
  }
  cout << v[0] + n * d;
  return 0;
}
