#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, j, c = 0, s = 0, f = 0, a, b;
  cin >> n >> m;
  vector<pair<long long int, long long int> > arr;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    arr.push_back(make_pair(b, a));
  }
  sort(arr.rbegin(), arr.rend());
  for (i = 0; i < m; i++) {
    if (n <= 0) {
      break;
    }
    c = min(arr[i].second, n);
    n -= c;
    s += arr[i].first * c;
  }
  cout << s << endl;
  return 0;
}
