#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010, inf = 1e9;
struct poi {
  int l, r, tim;
};
bool operator<(poi a, poi b) { return a.l < b.l || (a.l == b.l && a.r < b.r); }
set<poi> s;
vector<poi> v[maxn];
int n, K, l, r;
long long ans;
int cnt[maxn];
template <typename T>
inline void read(T &k) {
  int f = 1;
  k = 0;
  char c = getchar();
  while (c < '0' || c > '9') c == '-' && (f = -1), c = getchar();
  while (c <= '9' && c >= '0') k = k * 10 + c - '0', c = getchar();
  k *= f;
}
inline long long check(int mid) {
  for (int i = 1; i <= n; i++) cnt[i] = 0;
  int now = 0;
  long long sum = 0, nowsum = 0;
  for (int i = 1, j = 1; j <= n; j++) {
    for (int k = 0; k < v[j].size(); k++) {
      if (v[j][k].tim + 1 < i)
        nowsum += 1ll * (v[j][k].r - v[j][k].l + 1) * (i - v[j][k].tim - 1);
      if (v[j][k].tim + 1 <= i)
        now += v[j][k].r - v[j][k].l + 1;
      else
        cnt[v[j][k].tim + 1] += v[j][k].r - v[j][k].l + 1;
      cnt[j + 1] -= v[j][k].r - v[j][k].l + 1;
    }
    while (i <= j && now >= mid) nowsum += now, i++, now += cnt[i];
    sum += i - 1;
    ans += nowsum;
  }
  return sum;
}
int main() {
  read(n);
  read(K);
  s.insert((poi){1, inf, 0});
  for (int i = 1; i <= n; i++) {
    read(l);
    read(r);
    l++;
    set<poi>::iterator it1 = s.upper_bound((poi){l, inf, 0});
    it1--;
    for (set<poi>::iterator it = it1; it != s.end() && it->l <= r; it++)
      v[i].push_back((poi){max(l, it->l), min(r, it->r), it->tim});
    if (it1->l < l) s.insert((poi){it1->l, l - 1, it1->tim});
    set<poi>::iterator tmp;
    while (it1 != s.end() && it1->r <= r) {
      tmp = it1;
      it1++;
      s.erase(tmp);
    }
    if (it1 != s.end() && it1->l <= r)
      s.insert((poi){r + 1, it1->r, it1->tim}), s.erase(it1);
    s.insert((poi){l, r, i});
  }
  int l = 0, r = 1e9;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    ans = 0;
    if (check(mid) >= K)
      l = mid;
    else
      r = mid - 1;
  }
  ans = 0;
  long long tmp = check(l);
  printf("%lld\n", ans - (tmp - K) * l);
}
