#include <bits/stdc++.h>
typedef struct {
  long long a, b;
} box;
int cmp(const void *a, const void *b) {
  box *b1, *b2;
  b1 = (box *)a, b2 = (box *)b;
  return b2->b - b1->b;
}
int main(void) {
  long long n, m;
  scanf("%lld %lld", &n, &m);
  box b[m];
  int i;
  for (i = 0; i < m; i++) scanf("%lld %lld", &b[i].a, &b[i].b);
  qsort(b, m, sizeof(box), cmp);
  int res = 0;
  for (i = 0; i < m; i++) {
    res += (n < b[i].a ? n : b[i].a) * b[i].b;
    n -= (n < b[i].a ? n : b[i].a);
    if (n == 0) break;
  }
  printf("%i\n", res);
  return 0;
}
