#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &cout, vector<T> &a) {
  for (size_t i = 0; i < a.size(); ++i) cout << a[i] << " ";
  return cout;
}
template <typename T>
ostream &operator<<(ostream &cout, vector<vector<T> > &a) {
  for (size_t i = 0; i < a.size(); ++i) cout << a[i] << endl;
  return cout;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long ts, tf, t;
  cin >> ts >> tf >> t;
  int n;
  cin >> n;
  long long x;
  long long waitUntil = ts;
  long long tmin = ts, waitMin = LONG_LONG_MAX;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (x > waitUntil) {
      cout << waitUntil << endl;
      return 0;
    }
    waitUntil += t;
    if (waitUntil >= tf) break;
    if (waitUntil - (x - 1) < waitMin) {
      tmin = x - 1;
      waitMin = waitUntil - (x - 1);
    }
  }
  if (waitUntil + t <= tf) {
    cout << waitUntil << endl;
    return 0;
  }
  cout << tmin << endl;
  return 0;
}
