#include <bits/stdc++.h>
using namespace std;
bool sortby(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second > b.second);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p;
  while (m--) {
    int qq, pp;
    cin >> pp >> qq;
    p.push_back(make_pair(pp, qq));
  }
  sort(p.begin(), p.end(), sortby);
  int c = 0, i = 0, r = 0;
  for (i = 0; i < p.size(); i++) {
    if (c == n) break;
    int z = abs(n - c);
    int q = min(z, p[i].first);
    r += q * p[i].second;
    c += q;
  }
  cout << r << endl;
}
