#include<stdio.h>
#include<stdlib.h>
struct okk
{
int p, a;
};
int compare(const void* a, const void* b)
{
struct okk* a1 = (struct okk*)a;
struct okk* b1 = (struct okk*)b;
return (a1->p - b1->p);
}
int main()
{
int n, m;
scanf("%d %d", &n, &m);
if (n == 0 && m == 0)
{
printf("0\n");
return 0;
}
struct okk l[6000];
for(int i = 0; i < m; i++)
{
scanf("%d %d", &l[i].p, &l[i].a);
}
qsort(l, m, sizeof(struct okk), compare);
int sum = 0;
int price = 0;
int i = 0;
while (sum <= n && i < m)
{
if (l[i].a <= n)
{
sum += l[i].a;
price += l[i].a * l[i].p;
n -= l[i].a;
}
else
{
price += (l[i].a - n) * l[i].p;
break;
}
i++;
}
printf("%d", price);
return 0;
}