#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long s, e, t;
  cin >> s >> e >> t;
  long long n;
  cin >> n;
  if (n == 0) {
    cout << s << endl;
    return 0;
  }
  vector<long long> arr(n);
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<long long> ending(n);
  for (long long i = 0; i < n; i++) {
    if (i == 0) {
      ending[i] = max(arr[0], s) + t;
    } else {
      ending[i] = max(ending[i - 1], arr[i]) + t;
    }
  }
  pair<long long, long long> ans = make_pair(0, 0);
  if (arr[0] - 1 >= s) {
    ans = make_pair(t, s);
  } else {
    ans = make_pair(t + s - (arr[0] - 1), arr[0] - 1);
  }
  for (long long i = 1; i < n; i++) {
    if (arr[i] > ending[i - 1] && arr[i] - 1 + t <= e) {
      ans = min(ans, make_pair(t, ending[i - 1]));
    } else {
      long long come = arr[i] - 1;
      if (ending[i] <= e && arr[i] != arr[i - 1]) {
        ans = min(ans, make_pair(ending[i] - come, come));
      }
    }
  }
  if (ending[n - 1] + t <= e) {
    ans = min(ans, make_pair(t, ending[n - 1]));
  }
  cout << ans.second << endl;
}
