#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

typedef pair<int, int> P;

int n, m, p, q, r;
vector<P> data[2][3];

void calc(int t, int a, int b){
  int pos = 2, cnt = 0, nex = 1 - t, id = 0;
  int c[2] = {a, b};
  
  for(int i=0;i<3;i++) data[nex][i].clear();
  for(int i=0;i<3;i++){
    for(int j=0;j<data[t][i].size();j++){
      if(id == 2) data[nex][pos].push_back(data[t][i][j]);
      else{
        int val = cnt + data[t][i][j].second - data[t][i][j].first + 1;
        if(id == 0 && c[0] < val && c[1] < val){
          data[nex][pos].push_back(P(data[t][i][j].first, data[t][i][j].second - (val - c[id])));
          pos--;
          id++;
          data[nex][pos].push_back(P(data[t][i][j].second - (val - c[id-1]) + 1, data[t][i][j].second - (val - c[id])));
          pos--;
          id++;
          data[nex][pos].push_back(P(data[t][i][j].second - (val - c[id-1]) + 1, data[t][i][j].second));
        }else if(val < c[id]){
          data[nex][pos].push_back(data[t][i][j]);
        }else if(val == c[id]){
          data[nex][pos].push_back(data[t][i][j]);
          pos--;
          id++;
        }else if(val > c[id]){
          int tmp = val - c[id];
          data[nex][pos].push_back(P(data[t][i][j].first, data[t][i][j].second - tmp));
          pos--;
          id++;
          data[nex][pos].push_back(P(data[t][i][j].second - tmp + 1, data[t][i][j].second));
        }
      }
      cnt += data[t][i][j].second - data[t][i][j].first + 1;
    }
  }
}

int main(){
  while(cin >> n && n){
    for(int i=0;i<2;i++) for(int j=0;j<3;j++) data[i][j].clear();
    cin >> m >> p >> q >> r;
    data[0][0].push_back(P(1, n));
    for(int i=0;i<m;i++){
      int a, b;
      cin >> a >> b;
      calc(i%2, a, b);
    }
    /*for(int i=0;i<3;i++){
      for(int j=0;j<data[m%2][i].size();j++){
      cout << "(" << data[m%2][i][j].first << "-" << data[m%2][i][j].second << "), ";
      }
      cout << endl;
      }*/
    int ans = 0;
    int cnt = 0;
    for(int i=0;i<3;i++){
      for(int j=0;j<data[m%2][i].size();j++){
        P tmp = data[m%2][i][j];
        int len = tmp.second - tmp.first + 1;
        if(cnt <= p && q <= cnt + len){
          int v1 = tmp.first + (p - cnt - 1);
          int v2 = r - (v1 - 1);
          ans += max(0, min(v2, q - p + 1));
        }else if(p <= cnt && cnt + len <= q){
          int v1 = tmp.first - 1;
          int v2 = r - v1;
          ans += max(0, min(v2, len));
        }else if(cnt <= p && p <= cnt + len){
          int v1 = tmp.first + (p - cnt - 1); 
          int v2 = r - (v1 - 1);
          ans += max(0, min(v2, len - (p - cnt - 1)));
        }else if(cnt <= q && q <= cnt + len){
          int v1 = tmp.first - 1;
          int v2 = r - v1;
          ans += max(0, min(v2, q - cnt));
        }
        cnt += len;
      }
    }
    cout << ans << endl;
  }
}