#include <bits/stdc++.h>
using namespace std;
priority_queue<long long> pq;
int main() {
  long long ts, tf, t;
  cin >> ts >> tf >> t;
  int n;
  cin >> n;
  if (n == 0) {
    cout << ts;
    return 0;
  }
  while (n--) {
    long long x;
    cin >> x;
    pq.push(-x);
  }
  long long svt = ts;
  long long wt, res = 1e18;
  while (true) {
    if (pq.empty()) {
      if (svt + t <= tf) {
        cout << svt;
        return 0;
      }
      break;
    }
    if (svt + t <= tf and svt < -pq.top()) {
      cout << svt;
      return 0;
    }
    if (svt + t > tf) break;
    long long x = -pq.top();
    pq.pop();
    if (res > svt - x + 1) {
      res = svt - x + 1;
      wt = x - 1;
    }
    svt += t;
  }
  cout << wt;
}
