#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-7;
const double PI = acos(-1.0);
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
long long ts, tf, t, n;
long long num[100005];
int main() {
  while (scanf("%I64d%I64d%I64d%I64d", &ts, &tf, &t, &n) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%I64d", &num[i]);
    long long now = ts;
    if (num[1] > ts) {
      printf("%I64d\n", ts);
      continue;
    }
    long long an, anst = 1e12 + 9;
    for (int i = 1; i <= n; i++) {
      if (max((long long)0, now - num[i] + 1) < anst && num[i] - 1 + t <= tf) {
        anst = max((long long)0, now - num[i] + 1);
        an = num[i] - 1;
      }
      now = max(num[i], now) + t;
    }
    if (now + t <= tf)
      printf("%I64d\n", now);
    else
      printf("%I64d\n", an);
  }
  return 0;
}
