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