#include <iostream>
#include <algorithm>

using namespace std;

int c2[12] = {16, 18, 19, 25, 1, 2, 3, 4, 7, 8, 13, 14};
int c3[4] = {21, 24, 27, 10};

int main (){
    int a, year1, year2, counter = 0;
    cin >> a;
    while (a--){
        cin >> year1 >> year2;
        for (int i = year1; i <= year2; i++){
            if (any_of(begin(c2), end(c2), [=](int n){return n == i%28;})) counter+=2;
            else if(any_of(begin(c3), end(c3), [=](int n){return n == i%28;})) counter+=3;
            else counter++;
        }
    }
    cout << counter;
    return 0;
}