#include <bits/stdc++.h>

#define INFTY 2500

int getDiff(const int &a, const int &b) {
    int smin = a % 100, endmin = b % 100; //calc minutes
    int sh = a / 100, eh = b / 100; //calc hours

    return (endmin >= smin)
        ? (eh - sh) * 60 + (endmin - smin) :
        (eh - sh - 1) * 60 + (endmin + 60 - smin);
}

int collision (const std::pair<int, int> &a, const int &start, const int &end) {
    if (start <= a.first && end <= a.second && end >= a.first) return 1; //new watch starts earlier, ends earlier (a.first changes)
    if (start <= a.first && end > a.second && end >= a.first) return 2; //new watch starts earlier, ends later (two changes)
    if (start > a.first && end >= a.second && start <= a.second) return 3; //new watch starts later, ends later (a.sec changes)
    if (end < a.first) return 4; //new watch ends before current program (loop continues)
    return 0; //new watch starts later then a end
}

void merge(std::vector<std::pair<int, int> > &a) {

    int chk, chg;
    while (1) {
        chg = 0;
        std::sort(a.begin(), a.end());
        for (unsigned long i = a.size()-1; i > 0; i--) {
            if (a[i].first == INFTY) { continue; }
            chk = collision(a[i], a[i-1].first, a[i-1].second);
            if (chk == 1) {
                a[i-1].second = a[i].second;
                a[i].first = a[i].second = INFTY;
                chg++;
            }
            else if (chk == 2) {
                a[i].first = a[i].second = INFTY;
                chg++;
            } else if (chk == 3) {
                a[i-1].first = a[i].first;
                a[i].first = a[i].second = INFTY;
                chg++;
            }
        }
        if (chg == 0) break;
    }
}

void upload(std::vector<std::pair<int, int> > &a, int &watchstart, int &tmpstart, int &tmpend) {
    if (a.empty()) {
        a.push_back({watchstart, tmpstart});
    } else {
        int chk;
        bool isChanged = false;
        for (unsigned long k = 0; k < a.size(); k++) {
            chk = collision(a[k], watchstart, tmpstart);
            if (chk == 0 || a[k].first == INFTY) {
                a.push_back({watchstart, tmpstart});
                watchstart = tmpend;
                std::sort(a.begin(), a.end());
                isChanged = true;
            }
            if (chk == 1) {
                a[k].first = watchstart;
                isChanged = true;
            } else if (chk == 2) {
                a[k].first = watchstart;
                a[k].second = tmpstart;
                isChanged = true;
            } else if (chk == 3) {
                a[k].second = tmpstart;
                isChanged = true;
            }
            if (isChanged) break;
        }
        merge(a);
    }

}


int main()
{

    int N, start, end;

    while(1) {
        std::scanf("%d %d %d", &N, &start, &end);
        if (N == 0 && start == 0 && end == 0) break;
        std::vector<std::pair<int, int> > watch;
        int watchNum, watchstart, tmpstart, tmpend;

        for (int n = 0; n < N; n++) {
            std::scanf("%d", &watchNum);
            if (watchNum > 0) {
                std::scanf("%d %d", &tmpstart, &tmpend);
                if (tmpstart > start) upload(watch, start, tmpstart, tmpend);
                watchstart = tmpend;

                for (int j = 1; j < watchNum; j++) {
                    std::scanf("%d %d", &tmpstart, &tmpend);
                    upload(watch, watchstart, tmpstart, tmpend);
                    watchstart = tmpend;
                }
                if (watchstart < end) upload(watch, watchstart, end, end);
            }
        }

        int sum = 0;

        for (unsigned long i = 0; i < watch.size(); i++) {
            if (watch[i].first == INFTY) break;
            sum = std::max(sum, getDiff(watch[i].first, watch[i].second));
        }

        std::cout << sum << std::endl;

    }

    return 0;
}



Measured memory_bytes: 3068