#include <bits/stdc++.h>
using namespace std;
int pw(int k) {
  int g = 1;
  for (int f = 0; f < k; f++) g *= 10;
  return g;
}
struct vecteur {
  long X;
  long Y;
  long Z;
  double n;
};
long long produit(long A, long B, long C, long D) { return (A * B - C * D); }
double norme(long E, long F, long G) {
  return (sqrt((E * E) + (F * F) + (G * G)));
}
unsigned long long fact(int y) {
  unsigned long long h = 1;
  if (y == 0 || y == 1)
    return 1;
  else {
    for (unsigned long long j = 1; j < y; j++) {
      h *= (j + 1);
    }
    return h;
  }
}
long long counter(long long a) {
  long long c = 0;
  for (long long i = 1; i <= a; i++) {
    if (a % i == 0) c++;
  }
  return c;
}
bool isprime(long long a) {
  for (long long i = 2; i < a; i++) {
    if (a % i == 0) return 0;
  }
  return 1;
}
long long primeFactors(long long n) {
  long long j = 1, f = 0;
  while (n % 2 == 0) {
    if (f == 0) {
      j *= 2;
      f = 1;
    }
    n = n / 2;
  }
  f = 0;
  for (long long i = 3; i <= sqrt(n); i = i + 2) {
    f = 0;
    while (n % i == 0) {
      if (f == 0) {
        j *= i;
        f = 1;
      }
      n = n / i;
    }
  }
  if (n > 2) {
    j *= n;
  }
  return j;
}
long long det(long long x1, long long x2, long long x3, long long y1,
              long long y2, long long y3) {
  return (x1 * y2 + x2 * y3 + x3 * y1 - (x2 * y1 + x3 * y2 + x1 * y3));
}
unsigned long long dist(long long x1, long long y1, long long x2,
                        long long y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
int main() {
  int n, a, b, c, r, f = 1;
  cin >> n;
  if (n > 2) {
    cin >> a >> b;
    r = b - a;
    for (int i = 2; i < n; i++) {
      cin >> c;
      if (c - b != r) f = 0;
      b = c;
    }
    if (f)
      cout << c + r;
    else
      cout << c;
  } else {
    cin >> a >> b;
    cout << b + (b - a);
  }
  return 0;
}
