#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
long long a[maxn];
int main() {
  long long Start, End, du;
  scanf("%I64d%I64d%I64d", &Start, &End, &du);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  long long ans;
  long long minn = 1e12 + 100;
  for (int i = 1; i <= n; i++) {
    if (a[i] && max(Start, a[i] - 1) <= End - du) {
      if (Start - a[i] <= minn) {
        minn = Start - a[i] + 1;
        ans = min(a[i] - 1, Start);
      }
      Start = max(Start, a[i]) + du;
    }
  }
  if (Start + du <= End) ans = Start;
  printf("%I64d\n", ans);
}
