#include <bits/stdc++.h>
using namespace std;
long long arr[100005];
long long serve[100005];
int main(int argc, char const *argv[]) {
  long long ts, te, t;
  int n;
  cin >> ts >> te >> t;
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%lld", &arr[i]);
  arr[n++] = te - t + 1;
  sort(arr, arr + n);
  serve[0] = max(ts, arr[0]) + t;
  for (int i = 1; i < n; i++) {
    serve[i] = max(arr[i] + t, serve[i - 1] + t);
  }
  long long ans = 0;
  long long mintime = 1e15;
  if (arr[0] > 0) {
    ans = arr[0] - 1;
    mintime = max(0LL, ts - ans);
    if (arr[0] > ts) {
      ans = ts;
      mintime = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int pos = upper_bound(arr, arr + n, arr[i] - 1) - arr - 1;
    if (pos < 0) continue;
    if (serve[pos] + t <= te) {
      if (mintime > max(serve[pos] - (arr[i] - 1), 0LL)) {
        mintime = max(serve[pos] - (arr[i] - 1), 0LL);
        ans = arr[i] - 1;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
