#include <bits/stdc++.h>
using namespace std;
int N, Ans, Now, Last, Ld, Nd, flag;
namespace FastIO {
const int L = 1 << 15;
char buffer[L], *S, *T;
inline char getchar() {
  if (S == T) {
    T = (S = buffer) + fread(buffer, 1, L, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
inline int Get() {
  register char c;
  register int rec = 0, f = 1;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  while (c >= '0' && c <= '9')
    rec = (rec << 1) + (rec << 3) + (c - '0'), c = getchar();
  return rec * f;
}
}  // namespace FastIO
using FastIO::Get;
int main() {
  int i;
  N = Get();
  for (i = 1; i <= N; ++i) {
    Now = Get();
    Nd = Now - Last;
    if (Nd != Ld && i != 2 && i != 1) flag = 1;
    Last = Now;
    Ld = Nd;
  }
  if (flag)
    printf("%d\n", Now);
  else
    printf("%d\n", Now + Nd);
  return 0;
}
