#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
set<pair<pair<int, int>, int>> sp;
vector<pair<int, int>> q[300105];
set<pair<pair<int, int>, int>>::iterator split(int x) {
  auto it = sp.upper_bound({{x, (1 << 30)}, 0});
  it--;
  auto tmp = *it;
  sp.erase(it);
  sp.insert({{tmp.first.first, x}, tmp.second});
  return sp.insert({{x, tmp.first.second}, tmp.second}).first;
}
long long add[300105];
pair<long long, long long> cal(int mid) {
  memset(add, 0, sizeof add);
  int L = 0;
  long long single = 0, allR = 0;
  pair<long long, long long> ans = {0, 0};
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    for (auto p : q[i]) {
      if (p.first > L)
        add[p.first] += p.second;
      else {
        single += p.second;
        allR += (long long)(L - p.first + 1) * p.second;
      }
      add[i + 1] -= p.second;
    }
    while (L < i && single + add[L + 1] >= mid) {
      single += add[L + 1];
      L++;
      allR += single;
    }
    ans.first += L;
    ans.second += allR;
  }
  return ans;
}
void fmain(int ID) {
  scanf("%d%d", &n, &k);
  sp.insert({{1, 1e9}, 0});
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    int a, b;
    scanf("%d%d", &a, &b);
    auto r = split(b), l = split(a);
    for (auto it = l; it != r; it++) {
      q[i].push_back({it->second + 1, it->first.second - it->first.first});
    }
    sp.erase(l, r);
    sp.insert({{a, b}, i});
  }
  int l = 0, r = 1e9;
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    pair<long long, long long> ans = cal(mid);
    if (ans.first >= k)
      l = mid;
    else
      r = mid - 1;
  }
  int tar = cal(r).first >= k ? r : l;
  pair<long long, long long> ans = cal(tar);
  long long z = ans.second - (ans.first - k) * tar;
  printf("%lld\n", z);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
