#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b, boxes = 0, matches = 0;
  cin >> n >> m;
  vector<pair<int, int> > v(m);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v[i] = make_pair(b, a);
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < m; i++) {
    if (boxes + v[i].second <= n) {
      boxes += v[i].second;
      matches += v[i].second * v[i].first;
    } else {
      matches += (n - boxes) * v[i].first;
      boxes = n;
      break;
    }
  }
  cout << matches << endl;
  return 0;
}
