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