#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, d = 0, f = 0;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  d = a[1] - a[0];
  for (int i = 1; i < n; i++) {
    if ((a[i] - a[i - 1]) != d) {
      f = 1;
      break;
    }
  }
  if (f == 1) {
    cout << a[n - 1] << endl;
  }
  if (f == 0) {
    cout << a[n - 1] + d;
  }
  return 0;
}
