#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long ts, tf, t;
  cin >> ts >> tf >> t;
  int n;
  cin >> n;
  map<long long, int> T;
  for (int i = 0; i < n; ++i) {
    long long t;
    cin >> t;
    ++T[t];
  }
  long long bt = 0, ans = ts + t;
  for (const auto &s : T) {
    if (ts + t > tf) break;
    if (ts < s.first) {
      bt = ts;
      break;
    }
    if (s.first > 0) {
      long long ta = s.first - 1;
      if (ts + t - ta < ans) {
        ans = ts + t - ta;
        bt = ta;
      }
    }
    ts += t * s.second;
  }
  if (ts + t <= tf) bt = ts;
  cout << bt << '\n';
  return 0;
}
