#include <bits/stdc++.h>
using namespace std;
struct Inp {
  long long c, m;
};
bool cmp(const Inp& a, const Inp& b) { return a.m < b.m; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<Inp> inp(m);
  for (int(i) = 0; (i) < (m); ++(i)) {
    cin >> inp[i].c >> inp[i].m;
  }
  if (m > 1) sort(((inp).begin()), ((inp).end()), cmp);
  long long ans = 0;
  int cnt = n;
  for (auto(it) = (inp).rbegin(); (it) != (inp).rend(); ++(it)) {
    long long c = it->c;
    long long m = it->m;
    if (c <= cnt) {
      ans += m * c;
      cnt -= c;
    } else {
      ans += cnt * m;
      break;
    }
    if (cnt <= 0) break;
  }
  cout << ans << endl;
  return 0;
}
