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