#include <bits/stdc++.h>
using namespace std;
int l, n, p, t, arr[2][100002];
int main() {
  cin >> l >> n >> p >> t;
  vector<int> ends;
  for (int f = 0; f < n; f++) {
    cin >> arr[0][f] >> arr[1][f];
    ends.push_back(arr[1][f]);
  }
  if (p < 100) {
    vector<vector<vector<int> > > dp;
    vector<vector<int> > v1;
    vector<int> v;
    for (int f = 0; f < 102; f++) v.push_back(0);
    for (int f = 0; f < 2; f++) v1.push_back(v);
    for (int f = 0; f < 100004; f++) dp.push_back(v1);
    for (int f = n - 1; f >= 0; f--) {
      for (int f1 = p - 1; f1 >= 0; f1--) {
        for (int f2 = 0; f2 < 2; f2++) {
          int x = (arr[1][f] - arr[0][f] - f1) / p;
          int y = x * p + f1 + arr[0][f] + t;
          int i = lower_bound(ends.begin(), ends.end(), y) - ends.begin();
          int j = 0, z = 0;
          if (i == f) i++;
          if (i != ends.size()) {
            j = max(0, (y - arr[0][i])) % p;
            z = max(0, (y - arr[0][i])) / p;
          }
          if (f2) {
            dp[f][f2][f1] = max(dp[i][1][j] + x - z, dp[i + 1][0][0] + x);
          } else {
            dp[f][f2][f1] = max(max(dp[i][1][j] + x - z, dp[i + 1][0][0] + x),
                                dp[f + 1][0][0]);
          }
        }
      }
    }
    cout << dp[0][0][0] << endl;
  } else {
    int maxi = 0, mini = 0, i = 0;
    vector<pair<int, int> > v;
    for (int f = 0; f < n; f++) {
      int x = (arr[1][f] - arr[0][f]) % p + arr[0][f];
      for (; x <= arr[1][f]; x += p) {
        while (i < v.size() && x >= v[i].second) {
          if (maxi < v[i].first) {
            maxi = v[i].first;
            mini = v[i].second;
          } else if (maxi == v[i].first)
            mini = min(mini, v[i].second);
          i++;
        }
        mini = max(mini, arr[0][f]);
        v.push_back({maxi + (arr[1][f] - mini) / p,
                     mini + (arr[1][f] - mini) / p * p + t});
      }
    }
    while (i < v.size()) {
      maxi = max(maxi, v[i].first);
      i++;
    }
    cout << maxi << endl;
  }
}
