#include <bits/stdc++.h>
using namespace std;
int arr[104];
int main() {
  int n, avg, mn, flag;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  avg = 0;
  avg = arr[1] - arr[0];
  flag = 0;
  for (int i = 1; i < n; i++) {
    int diff = (arr[i] - arr[i - 1]);
    if (diff != avg) {
      flag = 1;
      break;
    }
  }
  if (flag == 1) {
    cout << arr[n - 1] << endl;
  } else {
    cout << arr[n - 1] + avg << endl;
  }
  return 0;
}
