#include <bits/stdc++.h>
using namespace std;
int main() {
  long long m, n, x, y, i, sum = 0, sum2 = 0;
  int p = 0;
  multimap<long long, long long, greater<long long> > a;
  cin >> m >> n;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    a.insert(make_pair(y, x));
  }
  map<long long, long long>::iterator it;
  for (it = a.begin(); it != a.end(); ++it) {
    sum2 += (*it).second;
    if (sum2 <= m) {
      sum += ((*it).first) * ((*it).second);
      if (sum2 == m) break;
    } else if (sum2 > m) {
      (*it).second = (*it).second - (sum2 - m);
      sum += ((*it).first) * ((*it).second);
      break;
    }
  }
  cout << sum;
}
