#include <bits/stdc++.h>
using namespace std;
template <class T>
using vv = vector<vector<T>>;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "{";
  for (int(i) = 0; (i) < (t.size()); ++(i)) {
    os << t[i] << ",";
  }
  os << "}" << endl;
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
template <class T>
inline bool MX(T &l, const T &r) {
  return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
  return l > r ? l = r, 1 : 0;
}
vector<string> s_p_l_i_t(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
void e_r_r(vector<string>::iterator it) {}
template <typename T, typename... Args>
void e_r_r(vector<string>::iterator it, T a, Args... args) {
  if (*it == " 1" || *it == "1")
    cerr << endl;
  else
    cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << ", ";
  e_r_r(++it, args...);
}
const long long MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(0);
  long long l, r, t, n;
  cin >> l >> r >> t >> n;
  vector<long long> a(n);
  for (int(i) = 0; (i) < (n); ++(i)) cin >> a[i];
  if (n == 0 || l < a[0]) {
    cout << l << endl;
    return 0;
  }
  long long cur = l, re = a[0] - 1;
  long long mn = l - re;
  for (int(i) = 0; (i) < (n); ++(i)) {
    cur = max(cur, a[i]) + t;
    if (i < n - 1 && cur < a[i + 1]) {
      re = cur;
      break;
    }
    if (cur + t > r) break;
    if (i == n - 1) {
      re = r - t;
    } else if (a[i] != a[i + 1]) {
      if (MN(mn, max(0ll, cur - (a[i + 1] - 1))))
        re = min({r - t, a[i + 1] - 1, cur});
    }
  }
  cout << re << endl;
  return 0;
}
