#include <bits/stdc++.h>
using namespace std;
int arr[1010];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  int dif = arr[2] - arr[1];
  for (int i = 2; i <= n; i++) {
    if ((arr[i] - arr[i - 1]) != dif) {
      cout << arr[n] << endl;
      return 0;
    }
  }
  cout << arr[n] + dif << endl;
  return 0;
}
