#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 20;
int n, k;
pair<int, int> a[N];
vector<pair<int, int> > add[N];
struct Node {
  int l, r, v;
  bool operator<(const Node &b) const { return l < b.l; }
};
set<Node> S;
set<Node>::iterator split(int x) {
  set<Node>::iterator it = --S.upper_bound({x, 0, 0});
  if (it->l == x) return it;
  Node z = *it;
  S.erase(it);
  S.insert({z.l, x - 1, z.v});
  return S.insert({x, z.r, z.v}).first;
}
void init() {
  S.insert({1, (int)1e9 + 7, 0});
  for (int i = 1; i <= n; ++i) {
    set<Node>::iterator epos = split(a[i].second + 1), st = split(a[i].first);
    for (set<Node>::iterator it = st; it != epos; it++) {
      add[i].push_back(make_pair(it->v + 1, it->r - it->l + 1));
    }
    S.erase(st, epos);
    S.insert({a[i].first, a[i].second, i});
  }
}
pair<long long, long long> check(int mid) {
  static long long arr[N];
  fill(arr, arr + n + 1, 0);
  long long sum = 0, cnt = 0, sum2 = 0;
  int l = 0, w = 0;
  for (int i = 1; i <= n; ++i) {
    for (auto &v : add[i]) {
      arr[max(v.first, l + 1)] += v.second;
      arr[i + 1] -= v.second;
      if (v.first <= l) sum += v.second * (l - v.first + 1ll);
    }
    while (l < i && w + arr[l + 1] >= mid) {
      w += arr[++l];
      sum += w;
    }
    cnt += l;
    sum2 += sum;
  }
  return make_pair(cnt, sum2);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i)
    scanf("%d%d", &a[i].first, &a[i].second), a[i].second--;
  init();
  int l = 0, r = 1e9, mid;
  long long low = 0, cnt = 0, sum = 0;
  while (l <= r) {
    mid = (l + r) >> 1;
    auto res = check(mid);
    if (res.first >= k) {
      l = (low = mid) + 1;
      sum = res.second;
      cnt = res.first;
    } else
      r = mid - 1;
  }
  printf("%lld\n", sum - (cnt - k) * low);
  return 0;
}
