#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > v;
  for (int i = 0; i < m; i++) {
    v.push_back({0, 0});
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end(), [](pair<int, int>& p1, pair<int, int>& p2) {
    return p1.second > p2.second;
  });
  int ans = 0;
  for (int i = 0; i < m && n; i++) {
    int x = min(v[i].first, n);
    ans += x * v[i].second;
    n -= x;
  }
  cout << ans;
  return 0;
}
