#include <iostream>
#include <list>

int n, m;
int p, q, r;

using Pair = std::pair<int, int>;

int main() {
    while(std::cin >> n, n) {
    std::cin >> m;
    std::cin >> p >> q >> r;
    --p, --q;
    
    std::list<Pair> list;
    
    list.push_back({0, n});
    
    int x, y;
    for(int i = 0; i < m; ++i) {
        std::cin >> x >> y;
        
        auto it = list.begin();
        decltype(it) xr[2], yr[2];
        xr[0] = it;
        int cnt = 0;
        while(1) {
            int c = it->second - it->first;
            cnt += c;
            
            if(cnt == x) {
                xr[1] = it;
                ++it;
                yr[0] = it;
                
                break;
            }else if(cnt > x) {
                auto p = Pair(it->first + c - (cnt - x), it->second);
                
                it->second = it->first + c - (cnt - x);
                
                ++it;
                
                it = xr[1] = yr[0] = list.insert(it, p);
                --xr[1];
                
                break;
            }
            ++it;
        }
        
        cnt = 0;
        y -= x;
        while(1) {
            int c = it->second - it->first;
            cnt += c;
            
            if(cnt == y) {
                yr[1] = it;
                break;
            }else if(cnt > y) {
                auto p = Pair(it->first + c - (cnt - y), it->second);
                
                it->second = it->first + c - (cnt - y);
                
                ++it;
                
                yr[1] = list.insert(it, p);
                
                --yr[1];
                break;
            }
            ++it;
        }
        
        ++yr[1];
        list.splice(list.end(), list, yr[0], yr[1]);
        ++xr[1];
        list.splice(list.end(), list, xr[0], xr[1]);
        
    }
    
    {
        int x = p, y = q + 1;
        auto it = list.begin();
        decltype(it) xr[2], yr[2];
        xr[0] = it;
        int cnt = 0;
        while(1) {
            int c = it->second - it->first;
            cnt += c;
            
            if(cnt == x) {
                xr[1] = it;
                ++it;
                yr[0] = it;
                
                break;
            }else if(cnt > x) {
                auto p = Pair(it->first + c - (cnt - x), it->second);
                
                it->second = it->first + c - (cnt - x);
                
                ++it;
                
                it = xr[1] = yr[0] = list.insert(it, p);
                --xr[1];
                
                break;
            }
            ++it;
        }
        
        cnt = 0;
        y -= x;
        while(1) {
            int c = it->second - it->first;
            cnt += c;
            
            if(cnt == y) {
                yr[1] = it;
                break;
            }else if(cnt > y) {

                auto p = Pair(it->first + c - (cnt - y), it->second);
                
                it->second = it->first + c - (cnt - y);
                
                ++it;
                
                yr[1] = list.insert(it, p);
                
                --yr[1];
                break;
            }
            ++it;
        }
        
        int ans = 0;
        ++yr[1];
        for(auto it = yr[0]; it != yr[1]; ++it) {
            if(it->second <= r) {
                ans += it->second - it->first;
            }else {
                if(it->first + 1 <= r) {
                    ans += r - it->first;
                }
            }
        }
        std::cout << ans << std::endl;
    }
    }
}