#include <bits/stdc++.h>
using namespace std;
int v[1005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &v[i]);
  int dif = v[2] - v[1];
  bool ok = 1;
  for (int i = 3; i <= n; ++i) {
    if (dif != v[i] - v[i - 1]) ok = 0;
  }
  if (ok)
    printf("%d\n", v[n] + dif);
  else
    printf("%d\n", v[n]);
  return 0;
}
