#include<iostream>
using namespace std;
#include<algorithm>
int n;
double v;
struct bag{
int weight;
int price;
};
bag a[105];
int cmp(bag a,bag b)
{
using namespace std;
#include<algorithm>
int n;
double v;
struct bag{
int weight;
int price;
};
bag a[105];
int cmp(bag a,bag b)
{
return a.price>b.price;
}
int main()
{
while(cin>>v>>n&&n)
{
int sum=0;
for(int i=0;i<n;i++)
{
cin>>a[i].price>>a[i].weight;
}
sort(a,a+n,cmp);
for(int i=0;i<n;i++){
if(v>0){
if(v>=a[i].weight)
{
sum=sum+a[i].price*a[i].weight;
v=v-a[i].weight;
}
else
if(v>0&&v<a[i].weight)
{
sum=sum+a[i].price*v;
v=0;
}
}
}
cout<<sum<<endl;
}
}
}
int main()
{
while(cin>>v>>n&&n)
{
int sum=0;
for(int i=0;i<n;i++)
{
cin>>a[i].price>>a[i].weight;
}
sort(a,a+n,cmp);
for(int i=0;i<n;i++){
if(v>0){
if(v>=a[i].weight)
{
sum=sum+a[i].price*a[i].weight;
v=v-a[i].weight;
}
else
if(v>0&&v<a[i].weight)
{
sum=sum+a[i].price*v;
v=0;
}
}
}
cout<<sum<<endl;
}
}