#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
const long long INF = 10000000000000LL;
long long tm[MAXN + 10], pre;
int main() {
  long long st, ed, t, val;
  int n;
  scanf("%I64d%I64d%I64d", &st, &ed, &t);
  ed--;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &tm[i]);
  tm[++n] = INF;
  sort(tm + 1, tm + 1 + n);
  if (tm[1] > st) {
    printf("%I64d\n", st);
    return 0;
  }
  pre = st - 1;
  long long ans = -1, wt = INF;
  for (int i = 1; i <= n; i++) {
    int lst = i;
    while (tm[lst + 1] == tm[i] && lst < n) lst++;
    long long used = t * (lst - i + 1);
    if (tm[i]) {
      if (pre < tm[i] - 1 && ed - pre >= t) {
        wt = 0;
        ans = pre + 1;
      }
      if (pre >= tm[i] - 1 && ed - pre >= t && pre - tm[i] < wt) {
        wt = pre - tm[i];
        ans = tm[i] - 1;
      }
    }
    pre = max(pre + used, tm[i] - 1 + used);
    i = lst;
  }
  printf("%I64d\n", ans);
  return 0;
}
