#include <bits/stdc++.h>
using namespace std;
long long a[100005];
int main(void) {
  long long i, j, n, m, start, endd, pass, COS, COST, ANS;
  COST = 1e15;
  cin >> start >> endd >> pass;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (i = 0; i < n; i++) {
    if (a[i] <= start) {
      COS = start - (a[i] - 1);
      if (COS < COST) {
        ANS = a[i] - 1;
        COST = COS;
      }
      start += pass;
    } else {
      COST = 0;
      ANS = min(a[i] - 1, start);
      start = a[i] + pass;
    }
    if ((start + pass) <= endd)
      continue;
    else
      break;
  }
  if (i == n && (start + pass) <= endd && COST) {
    ANS = start;
  }
  cout << ANS << endl;
}
