#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long a[N];
int main() {
  long long ts, tf, t;
  scanf("%I64d%I64d%I64d", &ts, &tf, &t);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", a + i);
  long long pos, ans = 1e18;
  long long last = ts;
  a[++n] = tf - t + 1;
  for (int i = 1; i <= n; i++) {
    long long x = a[i];
    if (a[i] != a[i - 1]) {
      long long tpos = min(a[i] - 1, last);
      long long tans = max(last - tpos, 0ll);
      if (max(last, tpos) + t > tf) break;
      if (tans < ans) {
        ans = tans;
        pos = tpos;
      }
    }
    last = max(x, last) + t;
  }
  printf("%I64d\n", pos);
  return 0;
}
