#include <bits/stdc++.h>
using namespace std;
long long ts, tf, t, n, x, ans, lim = 1000000000007;
int main() {
  cin >> ts >> tf >> t;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x <= tf - t) {
      if (max(ts, x - 1) <= tf - t && ts - (x - 1) < lim) {
        lim = ts - (x - 1);
        ans = min(ts, x - 1);
      }
      ts = max(ts, x) + t;
    }
  }
  if (ts <= tf - t) ans = ts;
  cout << ans << "\n";
}
