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