#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, n, s, f, t, l, j, k, z, x;
  cin >> s >> f >> t;
  cin >> n;
  vector<long long> a;
  long long v[n];
  for (i = 0; i < n; i++) cin >> v[i];
  if (n == 0) {
    cout << s;
    return 0;
  }
  l = s;
  for (i = 0; i < n; i++) {
    a.push_back(max(l, v[i]));
    l = max(l, v[i]) + t;
  }
  if (v[0] != 0) {
    x = v[0] - 1;
    k = s - x;
  } else {
    i = 0;
    while (i < n and v[i] == 0) i++;
    k = (i * t) + s;
    x = 0;
  }
  if (s < v[0]) {
    x = s;
    k = 0;
  }
  for (i = 1; i < n; i++) {
    if (v[i] > v[i - 1] + t and a[i - 1] + t + t <= f and
        k > abs(a[i - 1] - v[i] + 1 + t)) {
      if (a[i - 1] + t < v[i])
        x = a[i - 1] + t;
      else
        x = v[i] - 1;
      k = a[i - 1] + t - x;
    }
  }
  if (a[n - 1] + t + t <= f) x = a[n - 1] + t;
  cout << x;
  return 0;
}
