#include <bits/stdc++.h>
using namespace std;
const long long linf = (long long)1e18;
const int pw = 997;
const int N = 100009;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
long long c[N];
long long b[N];
long long e[N];
inline void prepare() {}
inline void solve() {
  long long s, f, t;
  scanf("%I64d%I64d%I64d", &s, &f, &t);
  int n;
  scanf("%d", &n);
  if (n == 0) {
    printf("%I64d", s);
    return;
  }
  e[0] = s;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &c[i]);
    b[i] = max(c[i], e[i - 1]);
    e[i] = b[i] + t;
  }
  if (b[1] > s) {
    printf("%I64d", s);
    return;
  }
  if (f - e[n] >= t) {
    printf("%I64d", e[n]);
    return;
  }
  long long pos = c[1] - 1;
  long long ans = s - pos;
  for (int i = 1; i <= n - 1; i++) {
    int j = i;
    while (c[j] == c[i]) {
      j++;
    }
    i = --j;
    if (b[i + 1] > e[i] && f - e[i] >= t) {
      printf("%I64d", e[i]);
      return;
    }
    if (ans > e[i] - (c[i + 1] - 1) && f - e[i] >= t) {
      pos = c[i + 1] - 1;
      ans = e[i] - pos;
    }
  }
  printf("%I64d", pos);
}
int main() {
  int tests = 1;
  prepare();
  while (tests--) {
    solve();
  }
}
