#include<stdio.h>
struct msg
{
int pi;
double mi;
}s[100],t;
int main()
{
int n, i, j, sum;
double v;
while(scanf("%lf%d",&v,&n)!=EOF)
{
if(v==0)break;
for(i=0;i<n;i++)
{
scanf("%d%lf",&s[i].pi,&s[i].mi);
}
for(i=0; i<n-1; i++)
{
for(j=0; j<n-i-1; j++)
{
if(s[j].pi<s[j+1].pi)
{
t = s[j];
s[j] = s[j+1];
s[j+1] = t;
}
}
}
sum=0;
for(j=0;j<n;j++)
{
if(v>=s[j].mi)
{
v=v-s[j].mi;
sum += s[j].pi * s[j].mi;
}
else
{
sum += s[j].pi * v;
break;
}
}
printf("%d\n",sum);
}
}
struct msg
{
int pi;
double mi;
}s[100],t;
int main()
{
int n, i, j, sum;
double v;
while(scanf("%lf%d",&v,&n)!=EOF)
{
if(v==0)break;
for(i=0;i<n;i++)
{
scanf("%d%lf",&s[i].pi,&s[i].mi);
}
for(i=0; i<n-1; i++)
{
for(j=0; j<n-i-1; j++)
{
if(s[j].pi<s[j+1].pi)
{
t = s[j];
s[j] = s[j+1];
s[j+1] = t;
}
}
}
sum=0;
for(j=0;j<n;j++)
{
if(v>=s[j].mi)
{
v=v-s[j].mi;
sum += s[j].pi * s[j].mi;
}
else
{
sum += s[j].pi * v;
break;
}
}
printf("%d\n",sum);
}
}