#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, a[100], temp1, temp2, flag = 0;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  temp1 = a[1] - a[0];
  for (i = 1; i < n - 1; i++) {
    temp2 = a[i + 1] - a[i];
    if (temp1 != temp2) {
      flag = 1;
      goto label;
    }
    temp1 = temp2;
  }
label:
  if (flag == 1)
    cout << a[n - 1] << endl;
  else
    cout << a[n - 1] + temp1 << endl;
  return 0;
}
