#include <bits/stdc++.h>
const int MAXN = 300010;
const int INF = 0x3f3f3f3f;
void gma(int& x, int y) { x < y ? x = y : 0; }
void gmi(int& x, int y) { x > y ? x = y : 0; }
struct itv {
  int l, r, id;
  bool operator<(itv b) const { return l < b.l; }
} ls[MAXN];
std::set<itv> S;
std::set<itv>::iterator split(int x) {
  auto it = S.lower_bound((itv){x + 1, 0, 0});
  if (it != S.begin()) {
    auto t = it;
    --t;
    if (t->r > x) {
      itv y = *t;
      S.erase(t);
      if (y.l != x) S.insert((itv){y.l, x, y.id});
      it = S.insert((itv){x, y.r, y.id}).first;
    }
  }
  return it;
}
std::pair<int, int> opt[MAXN << 3];
int cur[MAXN], bak;
int n, K;
void predo() {
  for (int i = 1; i <= n; ++i) {
    cur[i] = bak + 1;
    auto r = split(ls[i].r), l = split(ls[i].l);
    while (l != r) {
      opt[++bak] = std::pair<int, int>(l->id, l->l - l->r);
      S.erase(*l++);
    }
    opt[++bak] = std::pair<int, int>(i, ls[i].r - ls[i].l);
    S.insert(ls[i]);
  }
  cur[n + 1] = bak + 1;
}
int arr[MAXN], nowv, tov, now;
long long smk[MAXN], nowk;
void add(std::pair<int, int> x) {
  int at, v;
  std::tie(at, v) = x;
  arr[at] += v;
  smk[at] += (long long)at * v;
  tov += v;
  if (at >= now)
    nowv += v;
  else
    nowk += (long long)at * v;
}
void shr() { nowv -= arr[now], nowk += smk[now++]; }
std::pair<long long, long long> solve(int len) {
  memset(arr, 0, n + 1 << 2);
  memset(smk, 0, n + 1 << 3);
  tov = nowv = nowk = 0;
  now = 1;
  long long cnt = 0, sum = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = cur[i]; j < cur[i + 1]; ++j) add(opt[j]);
    while (now <= i && nowv >= len) shr();
    cnt += now - 1;
    sum += nowv * (now - 1ll) + nowk;
  }
  return std::make_pair(cnt, sum);
}
int main() {
  std::ios_base::sync_with_stdio(false), std::cin.tie(0);
  std::cin >> n >> K;
  int ll = INF, rr = 0;
  for (int i = 1; i <= n; ++i) {
    std::cin >> ls[i].l >> ls[i].r, ls[i].id = i;
    gmi(ll, ls[i].l), gma(rr, ls[i].r);
  }
  predo();
  int l = 0, r = rr - ll + 1, ans = 0;
  while (l <= r) {
    int mid = l + r >> 1;
    if (solve(mid).first >= K)
      l = mid + 1, ans = mid;
    else
      r = mid - 1;
  }
  auto tmp = solve(ans + 1);
  long long Ans = ans * (K - tmp.first) + tmp.second;
  std::cout << Ans << std::endl;
  return 0;
}
