#include <bits/stdc++.h>
using namespace std;
bool check(long long x, long long a[], int n) {
  int l = 1, r = n;
  while (l < r) {
    int middle = (l + r) / 2;
    if (a[middle] == x)
      return 1;
    else if (a[middle] > x)
      r = middle - 1;
    else
      l = middle + 1;
  }
  return 0;
}
int main() {
  long long start, finish, steps;
  cin >> start >> finish >> steps;
  int n;
  long long a[100001];
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  a[0] = -1;
  a[n + 1] = finish;
  long long res = 0, timeMin = 100000000000000;
  for (int i = 1; i <= n + 1; i++) {
    if (!check(start, a, n) && start < a[i] && start + steps <= finish) {
      res = start;
      break;
    }
    long long tmp;
    if (a[i] > 0 && a[i] != a[i - 1] && a[i] != a[i - 1] + 1 && a[i] <= start) {
      tmp = start + steps - (a[i] - 1);
      if (timeMin > tmp && start + steps <= finish) {
        res = a[i] - 1;
        timeMin = tmp;
      }
    }
    tmp = max(a[i], start) + 2 * steps - a[i];
    if (timeMin > tmp && start + 2 * steps <= finish && a[i] != a[i + 1]) {
      res = a[i];
      timeMin = tmp;
    }
    start = max(a[i], start) + steps;
  }
  cout << res;
  return 0;
}
