#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef struct {
    int begin;
    int end;
} Range;

inline int length(Range r) {
    return r.end - r.begin + 1;
}

void shuffle(vector<Range> &ranges, int x, int y) {
    int count = 1;
    int pos_x;
    int pos_y;
    vector<Range> tmp;
    tmp.clear();

    for (int i=0; i < ranges.size(); i++) {
        int len = length(ranges[i]);
            
        if (count + len > x) {
             Range new_range;
             new_range.end = ranges[i].end;

             ranges[i].end -= (count + len - 1 - x);
             if (count + len - 1 != x) {
                 new_range.begin = ranges[i].end + 1;
                 ranges.insert(ranges.begin() + i+1, new_range);
             }

             pos_x = i+1;
             break;
        }

        count += len;
    }

    count = 1;
    for (int i=0; i < ranges.size(); i++) {
        int len = length(ranges[i]);

        if (count + len > y) {
            Range new_range;
            new_range.end = ranges[i].end;

            ranges[i].end -= (count + len - 1 - y);
            if (count + len - 1 != y) {
                new_range.begin = ranges[i].end + 1;
                ranges.insert(ranges.begin() + i+1, new_range);
            }

            pos_y = i+1;
            break;
        }

         count += len;
     }

     for (int i=pos_y; i < ranges.size(); i++) {
         tmp.push_back(ranges[i]);
     }

     for (int i=pos_x; i < pos_y; i++) {
         tmp.push_back(ranges[i]);
     }

     for (int i=0; i < pos_x; i++) {
         tmp.push_back(ranges[i]);
     }

     ranges.swap(tmp);
}

int main() {
    while (1) {
        int n;
        int m;
        int p, q, r;
        int count;
        int num;
        Range first_range;
        vector<Range> ranges(1);
    
        scanf("%d", &n);
        if (n == 0) return 0;

        scanf("%d", &m);
        scanf("%d %d %d", &p, &q, &r);
    
        first_range.begin = 1;
        first_range.end = n;
        ranges[0] = first_range;
    
        for (int i=0; i<m; i++) {
            int x, y;
    
            scanf("%d %d", &x, &y);
            shuffle(ranges, x, y);
        }

        num = 0;
        count = 1;
        for (vector<Range>::iterator itr = ranges.begin(); itr != ranges.end(); itr++) {
             int start;
             int end;
             int len = length(*itr);
    
             if (count > q) break;
    
             if (count + len > p) {
                 end = itr->end;
                 start = itr->begin;
    
                 if (count < p) {
                     start += (p - count);
                 } 
    
                 if (count + len > q) {
                     end -= (count + len - q - 1);
                 }
    
                 if (start <= r) {
                     if (end <= r) {
                         num += end - start + 1;
                     } else {
                         num += r - start + 1;
                     }
                 }
             }
    
             count += len;
        }

        printf("%d\n", num);   
    }
}