#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, x, y, i, s = 0, k = 0;
  vector<pair<long long int, long long int> > v;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    v.push_back(make_pair(y, x));
  }
  sort(v.begin(), v.end());
  for (i = v.size() - 1; i >= 0; i--) {
    if (n > 0) {
      if (v[i].second >= n) {
        s = s + n * v[i].first;
        n = 0;
      } else {
        s = s + v[i].second * v[i].first;
        n = n - v[i].second;
      }
    } else {
      k = -1;
      cout << s << endl;
      break;
    }
  }
  if (k == 0) cout << s << endl;
}
