#include <bits/stdc++.h>
using namespace std;
const int maxn = 200030;
const int inf = 0x3f3f3f3f;
long long Begin, End, k, n;
long long num[maxn];
long long w = 1e18;
long long pos;
int main() {
  scanf("%lld %lld %lld", &Begin, &End, &k);
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &num[i]);
  }
  sort(num + 1, num + 1 + n);
  if (num[1] > Begin) {
    printf("%lld\n", Begin);
    return 0;
  }
  long long wait;
  for (long long i = 1; i <= n; i++) {
    if (num[i] < Begin) {
      wait = Begin - (num[i] - 1) + (i - 1) * k;
    } else {
      if (num[i] - 1 < Begin + (i - 1) * k) {
        wait = Begin + (i - 1) * k - num[i] + 1;
      } else {
        wait = 0;
      }
    }
    if (wait < w) {
      w = wait;
      pos = num[i] - 1;
    }
    long long endd = max((int)(Begin + i * k), (int)(num[i] + k));
    if (endd >= End) break;
  }
  long long las = max(Begin + n * k, num[n] + k);
  if (wait != 0) {
    for (long long i = las; i < End; i++) {
      if (End - i >= k && wait != 0) {
        wait = 0;
        pos = i;
        break;
      }
    }
  }
  printf("%lld\n", pos);
  return 0;
}
