#include <bits/stdc++.h>
using namespace std;
long long p, q, m, ans, minn, n, a[1000000];
int main() {
  scanf("%lld%lld%lld%lld", &p, &q, &m, &n);
  ans = minn = 1000000000000;
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++)
    if (a[i] > 0) {
      if (a[i] + m > q) break;
      long long last = max(a[i] - 1, p);
      if (last + m <= q && p - (a[i] - 1) < minn) {
        minn = p - (a[i] - 1);
        ans = min(p, a[i] - 1);
      }
      p = max(a[i], p) + m;
    }
  if (p + m <= q) ans = p;
  printf("%lld", ans);
}
