#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 7;
long long a[MAXN];
int main() {
  long long s, f, t;
  int n;
  scanf("%lld %lld %lld %d", &s, &f, &t, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  if (a[1] > s || n == 0) {
    printf("%lld\n", s);
    return 0;
  }
  vector<pair<long long, long long> > segs;
  long long open = s;
  for (int i = 1; i <= n; i++) {
    open = max(open, a[i]);
    segs.push_back(make_pair(open, open + t));
    open += t;
  }
  for (int i = 0; i < (int)segs.size() - 1; i++) {
    if (segs[i].second != segs[i + 1].first && segs[i].second + t <= f) {
      printf("%lld\n", segs[i].second);
      return 0;
    }
  }
  if (segs.back().second + t <= f) {
    printf("%lld\n", segs.back().second);
    return 0;
  }
  long long res = (long long)1e18;
  int respos = -1;
  for (int i = 1; i <= n; i++) {
    if (i == 1 || a[i - 1] != a[i]) {
      long long cur = (segs[i - 1].first - (a[i] - 1));
      if (cur < res && segs[i - 1].second <= f) {
        res = cur;
        respos = i;
      }
    }
  }
  printf("%lld\n", a[respos] - 1);
}
