#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[101];
  scanf("%d", &n);
  for (int(i) = 0; (i) < n; (i)++) scanf("%d", &a[i]);
  int b = a[1] - a[0];
  bool isb = true;
  for (int(i) = 0; (i) < n - 1; (i)++) a[i + 1] - a[i] == b ?: isb = false;
  if (isb)
    printf("%d\n", a[n - 1] + b);
  else
    printf("%d\n", a[n - 1]);
}
