#include #include using namespace std; int n, l, r, a[100009]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> l >> r; for (int j = r; j <= 100000; j++) { if (a[j] == 1) a[j] = 0; } for (int j = l; j < r; j++) { if (a[j] == 1) a[j + 1] = 1, a[j] = 0; } a[l] = 1; } int ret = 0; for (int i = 0; i <= 100000; i++) ret += a[i]; cout << ret << endl; return 0; }