#include <bits/stdc++.h>
using namespace std;
long long int tbegin, tend, t;
int n;
long long int a[100050];
int main() {
  cin >> tbegin >> tend >> t;
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  a[n++] = tend - t + 1;
  sort(a, a + n);
  pair<long long, long long> ans = make_pair(1e15, 1e15);
  long long endtime = tbegin;
  for (int i = 0; i < n; i++) {
    if (a[i] > 0) {
      pair<long long, long long> temp =
          make_pair(max((long long)0, endtime - a[i] + 1), a[i] - 1);
      if (endtime + t <= tend) ans = min(ans, temp);
    }
    endtime = max(endtime + t, a[i] + t);
  }
  cout << ans.second << endl;
  return 0;
}
