#include <bits/stdc++.h>
using namespace std;
struct Container {
  long a, b;
};
bool con_sorter(Container const &i, Container const &j) {
  if (i.b != j.b) return i.b < j.b;
}
int m, i;
long long n, sum = 0;
int main() {
  cin >> n >> m;
  Container con[m];
  for (i = 0; i < m; i++) {
    cin >> con[i].a >> con[i].b;
  }
  sort(con, con + m, &con_sorter);
  for (i = m - 1; n != 0 && i >= 0; i--) {
    if (n >= con[i].a) {
      n -= con[i].a;
      sum += con[i].a * con[i].b;
    } else {
      sum += n * con[i].b;
      n = 0;
    }
  }
  cout << sum;
  return 0;
}
