#include<iostream>
#include<sstream>
#include<map>
#include<string>
using namespace std;
int solveMethod(int m, string idsStr, string sizesStr)
{
map<int, int> idCost;
map<int, int> idSize;
stringstream ss1(idsStr);
stringstream ss2(sizesStr);
string temp1;
string temp2;
while(getline(ss1, temp1, ' ') && getline(ss2, temp2, ' '))
{
int id = stoi(temp1);
int size = stoi(temp2);
idCost[id] = idCost.count(id) ? idCost[id] + 1 : 1;
idSize[id] = size;
}
int sum = 0;
for(auto it = idCost.begin(); it != idCost.end(); it++)
{
int total = it->second * idSize[it->first];
idCost[it->first] = min(total, m + idSize[it->first]);
sum += idCost[it->first];
}
return sum;
}
int main()
{
int m;
cin >> m;
cin.ignore();
string idsStr;
string sizesStr;
getline(cin, idsStr);
getline(cin, sizesStr);
int res = solveMethod(m, idsStr, sizesStr);
cout << res << endl;
return 0;
}