#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
class range {
 public:
  range(int end) {
    _begin = 0;
    _end = end;
    _step = 1;
  }
  range(int begin, int end, int step = 1) {
    _begin = begin;
    _end = end;
    _step = step;
    if (!_step) _step = 1;
    if (_begin > _end) _step = -_step;
  }
  class iterator {
   public:
    iterator(int x, int s = 1) {
      n = x;
      step = s;
    }
    iterator& operator++() {
      n += step;
      return *this;
    }
    bool operator!=(const iterator& x) {
      return (step > 0) ? n < x.n : n > x.n;
    }
    int& operator*() { return n; }

   private:
    int n, step;
  };
  iterator begin() { return iterator(_begin, _step); }
  iterator end() { return iterator(_end, _step); }

 private:
  int _begin, _end, _step;
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int64_t ts, tf, t;
  cin >> ts >> tf >> t;
  int n;
  cin >> n;
  vector<int64_t> a(n);
  for (auto& i : a) cin >> i;
  if (n == 0 || a[0] > ts) {
    cout << ts << '\n';
    return 0;
  }
  int64_t anst = ts, spend = 10e18;
  queue<int64_t> q;
  for (int i = 0; i < n; i++) {
    if (a[i] != 0) {
      while (!q.empty() && a[i] - 1 >= q.front()) q.pop();
      if (q.empty()) {
        if (a[i] - 1 + t > tf) break;
        if (a[i] - 1 >= ts) {
          cout << a[i] - 1 << '\n';
          return 0;
        } else {
          if (spend > ts - (a[i] - 1)) {
            anst = a[i] - 1;
            spend = ts - (a[i] - 1);
          }
          q.push(ts + t);
        }
      } else {
        if (q.back() + t > tf) break;
        if (spend > q.back() - (a[i] - 1)) {
          anst = a[i] - 1;
          spend = q.back() - (a[i] - 1);
        }
        q.push(q.back() + t);
      }
    } else {
      if (q.empty()) {
        q.push(ts + t);
      } else {
        q.push(q.back() + t);
      }
    }
  }
  if (!q.empty() && q.back() + t <= tf) {
    anst = q.back();
  }
  cout << anst << '\n';
}
