#include <bits/stdc++.h>
using namespace std;
int a[110];
int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int x = a[1] - a[0];
  bool f = 1;
  for (int i = 2; i < n && f; i++)
    if (a[i] - a[i - 1] != x) {
      f = 0;
      break;
    }
  if (f || n == 2)
    cout << a[n - 1] + x << endl;
  else {
    cout << a[n - 1] << endl;
  }
  return 0;
}
