#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

int N;
int hit(int k, int i) {
    assert(0 <= k && k < N);
    assert(i == 1 || i == 10);
    return 1 << (2 * k + (i == 1 ? 0 : 1));
}

typedef long long LL;

int main(){
    while(cin >> N && N > 0){
        vector<int> low(N);
        vector<int> high(N);
        REP(i, N) cin >> low[i] >> high[i];
        LL ans = 0;

        for(int len = N; len <= 2 * N; len++) {
            static LL dp[20][20][1 << 12] = {};
            memset(dp, 0, sizeof(dp));

            REP(x, 10) if(x > 0) {
                int s = hit(0, 10);
                if(low[0] <= x && x <= high[0]) {
                    s |= hit(0, 1);
                }
                dp[1][x][s] = 1;
            }

            REP(i, len) if(i > 0) REP(x, 10) REP(s, 1 << (2 * N)) if(dp[i][x][s] > 0) REP(y, 10) {
                int ns = 0;
                REP(k, N - 1) if(s & hit(k, 1)) {
                    // 10
                    if(y > 0) ns |= hit(k + 1, 10);
                    // 1
                    if(low[k + 1] <= y && y <= high[k + 1]) {
                        ns |= hit(k + 1, 1);
                    }
                }
                REP(k, N) if(s & hit(k, 10)) {
                    assert(x != 0);
                    int d = x * 10 + y;
                    if(low[k] <= d && d <= high[k]) {
                        ns |= hit(k, 1);
                    }
                }
                // printf("(%d, %d, %x) -> (%d, %d, %x) : %d\n", i, x, s, i + 1, y, ns, dp[i][x][s]);
                dp[i + 1][y][ns] += dp[i][x][s];
            }

            LL subans = 0;
            REP(x, 10) REP(s, 1 << (2 * N)) if(s & hit(N - 1, 1)) {
                subans += dp[len][x][s];
            }
            // cout << len << " " << subans << endl;
            ans += subans;
        }
        cout << ans << endl;
    }
    return 0;
}