#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int main() {
  long long ts, tf, t;
  cin >> ts >> tf >> t;
  int n;
  cin >> n;
  long long tmp, mn = 1e12 + 1, res;
  while (n--) {
    scanf("%I64d", &tmp);
    if (tmp + t <= tf) {
      if (max(tmp - 1, ts) + t <= tf && ts - tmp + 1 < mn) {
        mn = ts - tmp + 1;
        res = min(ts, tmp - 1);
      }
      ts = max(ts, tmp) + t;
    }
  }
  if (ts + t <= tf) res = ts;
  cout << res << endl;
  return 0;
}
