#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const long long INFLL = 1e18;
const int OTHER = 1;
const int VASYA = 2;
long long ts, tf, t;
int n;
struct People {
  int tp;
  long long tm;
  People() {}
  People(int tp, long long tm) : tp(tp), tm(tm) {}
  bool operator<(const People &rhs) const {
    if (tm == rhs.tm) return tp > rhs.tp;
    return tm > rhs.tm;
  }
};
priority_queue<People> q;
int main() {
  scanf("%I64d%I64d%I64d%d", &ts, &tf, &t, &n);
  if (n == 0) {
    printf("%I64d\n", ts);
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    long long nowt;
    scanf("%I64d", &nowt);
    if (nowt != 0) q.push(People(VASYA, nowt - 1));
    q.push(People(OTHER, nowt));
  }
  q.push(People(VASYA, ts));
  long long nowt = ts, ans = INFLL, anst;
  while (!q.empty() && nowt <= tf - t) {
    while (!q.empty() && q.top().tm <= nowt && nowt <= tf - t) {
      People p = q.top();
      q.pop();
      if (p.tp == VASYA) {
        long long wt = nowt - p.tm;
        if (wt < ans) ans = wt, anst = p.tm;
      } else {
        nowt += t;
        q.push(People(VASYA, nowt));
      }
    }
    if (!q.empty() && nowt <= tf - t) nowt = q.top().tm;
  }
  printf("%I64d\n", anst);
  return 0;
}
