#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int main(void) {
  int n, m, a, b;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    v.push_back(make_pair(b, a));
  }
  sort(v.rbegin(), v.rend());
  long long ans = 0;
  int i = 0;
  while (n) {
    int del = min(n, v[i].second);
    ans += (long long)del * v[i].first;
    n -= del;
    i++;
    if (i == v.size()) break;
  }
  printf("%lld\n", ans);
}
