#include <bits/stdc++.h>
using namespace std;
int main() {
  long long ts, tf, te, tv, x;
  int n;
  cin >> ts >> tf >> te;
  cin >> n;
  long long t[n + 1];
  for (int i = 1; i <= n; i++) cin >> t[i];
  long long tw = LLONG_MAX;
  if (ts < t[1] || n == 0)
    tv = ts, tw = 0;
  else if (ts >= t[1]) {
    vector<long long> tt;
    tt.push_back(0);
    if (ts + te <= tf) tt.push_back(ts);
    for (int i = 2; i <= n; i++) {
      x = max(tt[i - 1] + te, t[i]);
      if (x + te > tf) break;
      tt.push_back(x);
    }
    int k = tt.size() - 1;
    if (tt[k] + 2 * te <= tf)
      tw = 0, tv = tt[k] + te;
    else {
      for (int i = 1; i <= k - 1; i++) {
        if (tt[i + 1] - (tt[i] + te) >= 1) {
          tw = 0, tv = tt[i] + te;
          break;
        }
      }
    }
    if (tw != 0) {
      for (int i = 1; i <= k - 1; i++) {
        if ((t[i + 1] - t[i] >= 1) && (tt[i] + te - t[i + 1] + 1 < tw)) {
          tw = tt[i] + te - (t[i + 1] - 1);
          tv = t[i + 1] - 1;
        }
      }
      if (ts - (t[1] - 1) < tw) {
        tw = ts - (t[1] - 1);
        tv = t[1] - 1;
      }
    }
  }
  cout << tv;
  return 0;
}
