#include<iostream>
#include<vector>

#define AMNT 4096

using namespace std;

typedef pair<int,int> range;
typedef vector< range > deck;

inline int quant(const range &r){
  return r.second-r.first+1;
}

int shuffle(int x, int y, deck &D, bool count = false, int r = 0){
  int i = 0;
  deck d1,d2,d3;
  int cts[D.size()];
  
  for(int i = 0; i < D.size(); ++i){
    cts[i] = (i==0?0:cts[i-1]) + (D[i].second-D[i].first)+1;
  }

  d1.reserve(AMNT);
  d2.reserve(AMNT);
  d3.reserve(AMNT);

  // part I
  int precnt=0, cnt=0;
  for(i; i < D.size(); ++i){
    range R=D[i];
    cnt += quant( R );
    if( cnt >= x ){
      d1.push_back( range( R.first, R.first + (x-precnt) - 1 ) );
      break;
    }else{
      d1.push_back( R );
    }
    precnt = cnt;
  }
  i=max(i-1,0);
  precnt=i<=1?0:cts[i-2];
  cnt=i<=0?0:cts[i-1];
  
  // part II
  bool first=true;
  for(i; i < D.size(); ++i){
    range R = D[i];
    cnt += quant( R );
    if( precnt <= x && precnt <= y && cnt > x && cnt > y ){
      d2.push_back( range( R.first + (x-precnt), R.first + (y-precnt) - 1 )  );
      break;
    }else if( cnt >= x && first ){
      d2.push_back( range( R.first + (x-precnt), R.second ) );
      first = false;
    }else if( cnt >= x && cnt < y  ){
      d2.push_back( R );
    }else if( cnt >= y ){
      d2.push_back( range( R.first, R.first + (y-precnt) - 1 ) );
      break;
    }
    precnt = cnt;
  }
  i=max(i-1,0);
  precnt=i<=1?0:cts[i-2];
  cnt=i<=0?0:cts[i-1];
  
  // part III
  first=true;
  for(i;i<D.size();++i){
    range R = D[i];
    cnt += quant( R );
    if( cnt > y && first ){
      d3.push_back( range( R.first + (y-precnt), R.second ) );
      first=false;
    }else if( !first ){
      d3.push_back( R );
    }
    precnt = cnt;
  }

/*
  cout << "D1" << endl;
  for(deck::iterator itd=d1.begin();itd!=d1.end();++itd){
    cout << '(' << itd->first << " - " << itd->second << ')' << endl;
  }cout << "D2" << endl;
  for(deck::iterator itd=d2.begin();itd!=d2.end();++itd){
    cout << '(' << itd->first << " - " << itd->second << ')' << endl;
  }cout << "D3" << endl;
  for(deck::iterator itd=d3.begin();itd!=d3.end();++itd){
    cout << '(' << itd->first << " - " << itd->second << ')' << endl;
  }
  cout << endl;
*/

  if( count ){
    int ret = 0;
    if( d1.back().second <= r ) ++ret;
    for(i = 0; i < d2.size(); ++i){
      range R = d2[i];
      //cout << R.first << ' ' << R.second << endl;
      if( R.first <= r ){
	ret += ( min(R.second,r) - R.first + 1);
      }
    }
    return ret;
  }


  int ni = 0;
  //  D.clear();
  D.resize( d1.size() + d2.size() + d3.size() );
  for(i = 0; i < d3.size(); ++i){ D[i] = d3[i]; } ni = d3.size();
  for(i = ni; i < ni+d2.size(); ++i){ D[i] = d2[i - ni]; } ni = d3.size() + d2.size();
  for(i = ni; i < ni+d1.size(); ++i){ D[i] = d1[i - ni]; }

  return 0;
}

int main()
{
  while(true){
    int n,m,p,q,r;
    deck D;
    scanf("%d",&n);
    if( n == 0 ) break;
    scanf("%d%d%d%d", &m, &p, &q, &r);
    D.push_back( range(1,n) );
    for(int i = 0; i < m; ++i){
      int x,y;
      scanf("%d%d", &x, &y);
      shuffle( x, y, D );
      // compress
      //CompressDeck( D );
      /*
      for(deck::iterator itd=D.begin();itd!=D.end();++itd){
	cout << '(' << itd->first << " - " << itd->second << ')' << endl;
      }
      cout << endl;
      */
    }
    printf("%d\n", shuffle( p, q, D, true, r ));
  }
  return 0;
}

Measured memory_bytes: 1172