#include <bits/stdc++.h>
const int N = 200010;
int Tc;
long long ts, tf, t, a[N], ans = -1, wait = 9999999999999999LL;
int n;
int main() {
  scanf("%I64d%I64d%I64d", &ts, &tf, &t);
  scanf("%d", &n);
  if (n == 0) return printf("%I64d\n", ts), 0;
  for (int i = 1; i <= n; ++i) scanf("%I64d", &a[i]);
  a[n + 1] = -1;
  if (a[1] <= ts) {
    long long now = ts;
    for (int i = 1; i <= n; ++i) {
      if (now > tf - t) break;
      long long tmp = now - a[i] + 1;
      if (tmp < wait) wait = tmp, ans = a[i] - 1;
      if (a[i] <= now)
        now += t;
      else
        return printf("%I64d\n", now), 0;
    }
    if (now <= tf - t) return printf("%I64d\n", now), 0;
    if (ans >= 0)
      printf("%I64d\n", ans);
    else {
      if (now <= tf - t)
        return printf("%I64d\n", now), 0;
      else
        for (;;)
          ;
    }
  } else
    printf("%I64d\n", ts);
  return 0;
}
