#include <bits/stdc++.h>
using namespace std;
int n;
long long s, t, x, ans1, ans2;
long long v[1000010];
int main() {
  scanf("%I64d%I64d%I64d", &s, &t, &x);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &v[i]);
  while (n && v[n] + x > t) n--;
  if (n == 0) {
    printf("%I64d\n", s);
    return 0;
  }
  ans1 = v[1] - 1;
  ans2 = s - ans1;
  long long cur = s;
  for (int i = 1; i <= n; i++) {
    if (v[i] <= cur)
      cur += x;
    else
      cur = v[i] + x;
    if (i < n && v[i] == v[i + 1]) continue;
    if (i < n) {
      long long tmp = v[i + 1] - 1, tt = max(0ll, cur - tmp);
      if (tt < ans2) ans1 = tmp, ans2 = tt;
    }
  }
  if (cur + x <= t) {
    ans1 = cur, ans2 = 0;
  }
  printf("%I64d\n", ans1);
  return 0;
}
