#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000007;
long long a[maxn], b[maxn], c[maxn];
int main() {
  long long ts, tf, t;
  scanf("%lld %lld %lld", &ts, &tf, &t);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", a + i);
  }
  int m = 0;
  for (int i = 0; i < n; ++i) {
    int k = 0;
    while (i + 1 < n && a[i + 1] == a[i]) {
      ++k;
      ++i;
    }
    b[m] = a[i];
    c[m] = k + 1;
    ++m;
  }
  long long x = ts;
  long long minx = (long long)1e15;
  long long minz = (long long)1e15;
  bool e = false;
  for (int i = 0; i < m; ++i) {
    if (i > 0) {
      x = max(x, b[i - 1]) + t * c[i - 1];
    }
    long long p;
    if (x < b[i] - 1) {
      p = x;
    } else {
      p = b[i] - 1;
    }
    long long o = x + t;
    if (o > tf) {
      e = true;
      break;
    }
    if (x - p < minz) {
      minz = x - p;
      minx = p;
    }
  }
  if (!e) {
    x = max(x, b[m - 1]) + t * c[m - 1];
    if (tf - t >= x) {
      minx = tf - t;
    }
  }
  printf("%lld\n", minx);
  return 0;
}
