#include <bits/stdc++.h>
using namespace std;
long long s, f, dT, last, ans, dtmin, x, y;
int i, n, k;
long long tin[100001], dt[100001], tout[100001];
int main() {
  cin >> s >> f >> dT;
  cin >> n;
  if (n == 0) {
    cout << s << endl;
    return 0;
  }
  last = 0;
  k = 0;
  for (i = 1; i <= n; i++) {
    cin >> tin[i];
    if (tin[i] > last) {
      tin[++k] = tin[i];
      dt[k] = dT;
      last = tin[i];
    } else
      dt[k] += dT;
  }
  n = k;
  last = s;
  for (i = 1; i <= n; i++)
    if (last >= tin[i]) {
      tout[i] = last + dt[i];
      last = tout[i];
    } else {
      tout[i] = tin[i] + dt[i];
      last = tout[i];
    }
  ans = dtmin = f;
  if (tout[n] + dT <= f)
    ans = tout[n];
  else {
    if (tin[1] > s) {
      cout << s << endl;
      return 0;
    }
    for (i = 1; i <= n; i++) {
      x = tin[i] - 1;
      if (i > 1 && tout[i - 1] <= x) {
        ans = tout[i - 1];
        dtmin = dT;
        break;
      }
      if (x + dT >= f) break;
      if (i == 1)
        y = s + dT;
      else
        y = tout[i - 1] + dT;
      if (y < f && y - x < dtmin) {
        dtmin = y - x;
        ans = x;
      }
      if (dtmin == dT) break;
    }
  }
  cout << ans << endl;
}
