#include <bits/stdc++.h>
using namespace std;
vector<pair<long, long> > vp;
bool sortbysec(const pair<int, int>& a, const pair<int, int>& b) {
  return a.second > b.second;
}
int main() {
  long capacity, container;
  cin >> capacity >> container;
  while (container--) {
    int x, y;
    cin >> x >> y;
    vp.push_back(make_pair(x, y));
  }
  sort(vp.begin(), vp.end(), sortbysec);
  long ans = 0;
  for (auto obj : vp) {
    if (capacity > 0) {
      long data = (obj.first > capacity) ? capacity : obj.first;
      ans += (data * obj.second);
      capacity -= obj.first;
    }
  }
  cout << ans << endl;
  return 0;
}
