#include <bits/stdc++.h>
int main(int argc, const char* argv[]) {
  int n;
  std::cin >> n;
  int step = 0;
  int prev = 0;
  int first = 0, second = 0;
  bool prog = true;
  int x = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> x;
    if (i == 0)
      first = x;
    else if (i == 1) {
      second = x;
      step = second - first;
      prev = x;
    } else {
      if ((x - prev) != step) prog = false;
      prev = x;
    }
  }
  if (prog)
    std::cout << x + step;
  else
    std::cout << x;
  return 0;
}
