#include <bits/stdc++.h>
using namespace std;
int pro(int *a, int *b, int t, int s) {
  int k = 0;
  for (int i = 1; i < t; i++) {
    if (b[i] != s) {
      return 2;
    }
    if (b[i] == 0) {
      k++;
    }
  }
  if (k == (t - 1)) {
    return 3;
  }
  return 1;
}
int main() {
  int t, a[105], b[105];
  a[0] = 0;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> a[i];
    b[i - 1] = a[i] - a[i - 1];
  }
  if (t == 1) {
    cout << a[1];
  }
  int c = pro(a, b, t, b[1]);
  if (c == 3) {
    cout << a[1];
  } else if (c == 1) {
    cout << a[t] + b[1];
  } else {
    cout << a[t];
  }
  return 0;
}
