#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, f, n, m, res, t, l, r, x, y, z;
vector<pair<int, int> > vp;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &a, &b);
    vp.push_back(make_pair(b, a));
  }
  sort(vp.rbegin(), vp.rend());
  l = 0;
  while (t < n && l < vp.size()) {
    if (vp[l].second <= 0) {
      l++;
      continue;
    }
    x = min(n - t, vp[l].second);
    vp[l].second -= x;
    res += (x * vp[l].first);
    t += x;
  }
  cout << res << endl;
  return 0;
}
