#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int ts, tf, m, bb, n, ans;
  long long int wt = 1e12 + 5;
  scanf("%lld%lld%lld", &ts, &tf, &m);
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &bb);
    if (bb && bb + m <= tf) {
      if (max(ts, bb - 1) + m <= tf && ts - bb + 1 < wt) {
        wt = ts - bb + 1;
        ans = min(bb - 1, ts);
      }
      ts = max(ts, bb) + m;
    }
  }
  if (ts <= tf - m) ans = ts;
  printf("%lld\n", ans);
  return 0;
}
