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