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