#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long t[n];
  for (long long i = 0; i < n; ++i) cin >> t[i];
  long long d = t[1] - t[0];
  bool a = 1;
  for (long long i = 1; i < n - 1; ++i) {
    if (t[i + 1] - t[i] != d) {
      a = false;
      break;
    }
  }
  if (a)
    cout << t[n - 1] + d;
  else
    cout << t[n - 1];
  return 0;
}
