#include <iostream>
#include <string>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
using namespace std;

int n;
vector<pair<int, int> > v;
int arr[1002][366];
bool visited[1002][366];
int dx[8] = {-1, -1, 0, 1, 1, 1 ,0, -1};
int dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
queue<pair<int, int> > q;
int sum = 0;

bool camp(const pair<int, int> &a, const pair<int, int> &b){
    if(a.first == b.first){
        return a.second > b.second;
    }
    return a.first < b.first;
}

bool cango(int x, int y){
    return 0 <= x && 0 <= y && x < 366 && y < 366 && arr[x][y] == 1 && !visited[x][y];
}

void func(){
    int min_x = q.front().first;
    int min_y = q.front().second;
    int max_x = 0;
    int max_y = 0;
    int flag = 0;
    while(!q.empty()){
        int x = q.front().first;
        int y = q.front().second;
        q.pop();

        for(int i = 0; i < 8; i++){
            int nx = x + dx[i];
            int ny = y + dy[i];

            if(cango(nx, ny)){
                flag = 1;
                q.push(make_pair(nx, ny));
                visited[nx][ny] = 1;
                max_x = max(max_x, nx);
                max_y = max(max_y, ny);
            }
        }
    }
    if(flag == 0){
        sum += 1;
        return;
    }
    max_x++;
    max_y++;
    sum += (max_x - min_x) * (max_y - min_y);
    //cout << sum << '\n';
    return;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i++){
        int start, end;
        cin >> start >> end;
        v.push_back(make_pair(start, end));
    }
    sort(v.begin(), v.end(), camp);

    int max_x = 0;
    for(int i = 0; i < n; i++){
        int x = v[i].first;
        int y = v[i].second;
        max_x = max(max_x, y);
        for(int j = 0; j < n; j++){
            if(arr[j][x] == 0){
                for(int k = x; k <= y; k++){
                    arr[j][k] = 1;
                }
                break;
            }
        }
    }

    // for(int i = 0; i < n; i++){
    //     for(int j = 0; j <= max_x; j++){
    //         cout << arr[i][j] << ' ';
    //     }
    //     cout << '\n';
    // }

    for(int i = 0; i < n; i++){
        for(int j = 0; j <= max_x; j++){
            if(arr[i][j] == 1 && !visited[i][j]){
                q.push(make_pair(i, j));
                visited[i][j] = 1;
                func();
            }
        }
    }

    cout << sum;
}