#include <stdio.h>
#include <stdbool.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	int b[n];
	for (int i = 0; i < n; i++) b[i] = ri();
	
	int res = 0;
	for (int i = 1; i <= 1000; i++) {
		bool ok = true;
		for (int j = 0; j < n; j++) if (i < a[j] || i > b[j]) ok = false;
		if (ok) res++;
	}
	
	printf("%d\n", res);
	return 0;
}


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

int main() {
    int64_t n;
    cin >> n;
    int len = to_string(n).size();
    int ans = 0;
    if (len % 2 == 0) {
        int n1 = n / pow(10, len / 2);
        int n2 = n % (int64_t)pow(10, len / 2);
        if (n1 > n2) ans--;
        ans += (n1 - pow(10, len / 2 - 1) + 1);
    }
    for (int i = 2; i <= 12; i += 2) {
        if (n >= pow(10, i)) ans += (9 * pow(10, i / 2 - 1));
    }
    cout << ans << endl;
    return 0;
}
