#include <bits/stdc++.h>
using namespace std;
long long int ts, tf, t, a[100005], l[100005], r[100005], n, cur,
    bef = -1, cnt[100005], an = 2e15, ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  scanf("%lld%lld%lld%lld", &ts, &tf, &t, &n);
  long long int j = 1, i;
  if (n == 0) {
    printf("%lld", ts);
    return 0;
  }
  for (i = 1; i <= n; i++) {
    scanf("%lld", &cur);
    if (cur == bef)
      cnt[j - 1]++;
    else {
      a[j] = cur;
      cnt[j] = 1;
      j++;
    }
    bef = cur;
  }
  cur = ts;
  for (i = 1; i < j; i++) {
    if (cur >= a[i]) {
      l[i] = cur;
      r[i] = (t * cnt[i]) + cur - 1;
    } else {
      l[i] = a[i];
      r[i] = (t * cnt[i]) + a[i] - 1;
    }
    cur = r[i] + 1;
  }
  cur = ts;
  bool flag = false;
  for (i = 1; i < j; i++) {
    if (r[i] > tf)
      break;
    else if (cur != l[i]) {
      printf("%lld", cur);
      return 0;
    } else if (a[i] - 1 >= 0 && (l[i] - a[i] + 1) < an) {
      ans = a[i] - 1;
      an = (l[i] - a[i] + 1);
    }
    cur = r[i] + 1;
    flag = true;
  }
  if (flag) cur--;
  if (flag && cur + t <= tf && i < j) {
    if (a[i] <= cur + 1 && (cur - a[i] + 2) < an) {
      ans = a[i] - 1;
      an = (cur - a[i] + 2);
    } else {
      printf("%lld", cur + 1);
      return 0;
    }
  } else if (flag && i >= j && cur + t <= tf) {
    printf("%lld", cur + 1);
    return 0;
  } else if (!flag) {
    if (a[i] > cur) {
      printf("%lld", cur);
      return 0;
    } else {
      printf("%lld", a[i] - 1);
      return 0;
    }
  }
  printf("%lld", ans);
  return 0;
}
