const [_n, ..._edges] = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/)
const n = Number(_n)
const edges = new Array(n).fill().map(() => new Set());

for (const _edge of _edges) {
  const [u, v] = _edge.split(/\s/).map(v => Number(v) - 1)
  edges[u].add(v)
  edges[v].add(u)
}

let result = 0;
for (let l = 0; l < n; l++) {
  for (let r = l; r < n; r++) {
    let vertices = [...new Array(r - l + 1).keys()].map((i) => i + l)
    result += 1;
    let connectedEdges = edges[vertices.pop()]
    while (vertices.length > 0) {
      let verticeAdded = false
      vertices = vertices.filter(vertice => {
        if (connectedEdges.has(vertice)) {
          verticeAdded = true
          connectedEdges = new Set([...connectedEdges, ...edges[vertice]])
          return false
        }
        return true
      })
      if (!verticeAdded) {
        result += 1;
        connectedEdges = edges[vertices.pop()]
      }
    }
  }
}
console.log(result)