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