#include <bits/stdc++.h>
using namespace std;
const long long oo = 0x3f3f3f3f3f3f3f3fll;
const int LGN = 25;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
int n, m;
long long ts, tf, t, vis[N], arrive[N], cost[N];
long long ava;
int main() {
  std::ios::sync_with_stdio(false);
  scanf("%lld", &(ts)), scanf("%lld", &(tf)), scanf("%lld", &(t));
  ava = tf - ts;
  scanf("%d", &(n));
  if (n == 0) {
    printf("%lld\n", ts);
    return 0;
  }
  for (long long i = 1, __R = n; i <= __R; i++) scanf("%lld", &(vis[i]));
  vis[++n] = oo;
  bool done = false;
  for (long long i = 1, __R = n; i <= __R; i++) {
    m++;
    arrive[m] = vis[i];
    for (long long j = i, __R = n; j <= __R; j++) {
      if (vis[j] != vis[i]) break;
      cost[m] += t;
      if (cost[m] >= ava) {
        done = true;
        break;
      }
      i = j;
    }
    if (done) break;
  }
  if (m == 0) {
    printf("%lld\n", vis[1] - 1);
    return 0;
  }
  long long ans, wait = oo;
  if (arrive[1] > 0) {
    ans = min(arrive[1] - 1, ts);
    wait = ts - ans;
  }
  long long sim = max(arrive[1], ts) + cost[1];
  for (long long i = 2, __R = m; i <= __R; i++) {
    if (sim >= tf) {
      printf("%lld\n", ans);
      return 0;
    }
    long long alt = min(arrive[i] - 1, sim);
    long long waitalt = sim - alt;
    if (waitalt < wait && alt + t <= tf) wait = waitalt, ans = alt;
    sim = max(sim, arrive[i]) + cost[i];
  }
  printf("%lld\n", ans);
  return 0;
}
