using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

struct Place
{
    public long a, k;
    public int g;
    public Place(long[] b)
    {
        a = b[0];
        k = Math.Min(b[0], b[1]);
        g = Convert.ToInt32(b[1]);
    }
}

class Program
{
    static int cmp(Place a, Place b)
    {
        return b.g - a.g;
    }
    static void Main()
    {
        StreamReader read = new StreamReader(new FileStream("castle.in", FileMode.Open));
        StreamWriter write = new StreamWriter(new FileStream("castle.out", FileMode.Create));
        long[] ns = read.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
        Place[] p = new Place[ns[0]];
        int i;
        for (i = 0; i < ns[0]; i ++)
            p[i] = new Place(read.ReadLine().Split().Select(x => long.Parse(x)).ToArray());
        Array.Sort(p, cmp);
        long ans = 0;
        HashSet<long> h = new HashSet<long>();
        for (i = 0; i < ns[0]; i ++)
        {
            if (h.Count != 0)
            {
                long max = h.Max(), gg = Math.Min(p[i].k, p[i].a);
                while (max >= gg && ns[1] != 0)
                {
                    ns[1]--;
                    h.Remove(max);
                    if (h.Count != 0)
                        max = h.Max();
                    else
                        break;
                }
            }
            if (ns[1] * p[i].k < p[i].a)
            {
                ans += (p[i].a - ns[1] * p[i].k);
                break;
            }
            else
            {
                if (p[i].a % p[i].k != 0)
                    h.Add(p[i].a % p[i].k);
                ns[1] -= (p[i].a / p[i].k);
            }
        }
        ans += h.Sum();
        for (i = i + 1; i < ns[0]; i ++)
            ans += p[i].a;
        write.WriteLine(ans);
        read.Close();
        write.Close();
    }
}